javascript - Making a POST HttpRequest (XMLHttpRequest) in Dart -


i try submit simple post httprequest in dart. according docs, method should request.onload.add instead of request.onload.listen, 1 using. yet arrived here because `onload.add' did not exist. :o issue: no errors, no submit, no success message.

void main() {   query("#sample_text_id")     ..text = "click me!"     ..onclick.listen(submithttprequest('test.php')); }  void submithttprequest(string phpfile, [json, callback(int status)]) {   print('yeeep');   var request = new httprequest();   request.open('post', 'php/$phpfile');   request.onload.listen((event) { print('event'); }, ondone: ()    {       print('loaded');       handleresponse(request.status);       if(callback != null) {         callback(request.status);       }    }, onerror: (e) { print('err' + e.tostring()); });   } 

the output is

invalid css property name: -webkit-touch-callout yeeep 

i have no idea first line comes from, pretty sure generated , none of code.

the doc on default httprequest constructor seems outdated.

to make work :

  • you have add request.send(); @ end of submithttprequest send request.
  • fix way add listener on click. in original code add result of submithttprequest('test.php') (that null) ..onclick.listen(). should have done : ..onclick.listen((_) => submithttprequest('test.php')).

here's working version :

import 'dart:html';  void main() {   query("#sample_text_id")     ..text = "click me!"     ..onclick.listen((_) => submithttprequest('test.php')); }  void submithttprequest(string phpfile, [json, callback(int status)]) {   print('yeeep');   var request = new httprequest();   request.open('post', 'php/$phpfile');   request.onload.listen((event) { print('event'); }, ondone: () {     print('loaded');     handleresponse(request.status);     if(callback != null) {       callback(request.status);     }   }, onerror: (e) { print('err' + e.tostring()); });   request.send(json); } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -