5

I am trying to send some data from Dart to PHP... This is the code i am using to send the data from Dart:

button.onClick.listen((e) {
  var req = new HttpRequest();


  req.onReadyStateChange.listen((HttpRequestProgressEvent e) {
    if (req.readyState == HttpRequest.DONE) {
      print('Data submitted!');
    }
  });


  req.open('POST', form.action);
  req.send('hello from dart');

});

In my PHP file I am trying to use the string i have send from dart, but count($_POST) returns 0. $_POST seems to be empty...

Dart code DOES trigger the php script and 'Data submitted' is printed...

2 Answers 2

7

This is actually related to your PHP configuration. You can access the POST'd data with PHP's reserved variable: $HTTP_RAW_POST_DATA However the preferred method is to use php://input

Sign up to request clarification or add additional context in comments.

Comments

2

I am very new to Dart, but you can use FormData in the send. So a quick and dirty way could be.

    var data_form = new FormData(query('#My_form'));

    button.onClick.listen((e){
           var request = new HttpRequest():
           request.open('POST', 'http://Localhost/form_data.php');
           request.send(data_form);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.