Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending data from Dart to PHP using POST method

Tags:

html

dart

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...

like image 667
deloki Avatar asked Apr 10 '13 17:04

deloki


2 Answers

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

like image 140
Matt B Avatar answered Nov 02 '22 00:11

Matt B


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);
like image 45
thaDanzar Avatar answered Nov 02 '22 00:11

thaDanzar