您的位置:首页 > 理论基础 > 计算机网络

Using POST method in XMLHTTPRequest(Ajax)

2008-10-09 17:15 543 查看
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.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);

注意params中值的编码,用函数encodeURIComponent来编码特殊字符。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: