HTTP POST failed
Posted: 07:12, 10 Mar 2015
I am trying to post some data from mobile app to a remove server. I found the following JS code and tried it in the evothings JavaScript Workbench, it worked well. But when I pushed the same code to mobile app with some HTML (document.getElementById("response").innerHTML = , to display responseText coming back), I never received http.status == 200, the status is always 0, never received any resonseText back, either. Why is that?
Thanks a lot for your time and help! -John
Thanks a lot for your time and help! -John
Code: Select all
var http = new XMLHttpRequest();
var url = "http://24.218.156.245:8080/DataIntegrator/JsonHandler";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);