html tool

2017年7月26日星期三

js-post-demo


https://stackoverflow.com/questions/9713058/send-post-data-using-xmlhttprequest



accepted
This code demonstrates on how to do this.

Here is just the listing from that page, in case the above link goes down again:
var http = new XMLHttpRequest();
var url = "get_data.php";
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.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
http.send(params);

没有评论:

发表评论