我正在尝试使用POST方法编写一个XMLHttpRequest。我过去通过GET方法成功地使用了XMLHttpRequest,但在POST方面遇到了困难。
下面是我的代码:
var xmlhttp = null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "http://www.mysite.com/script.php";
var params = "var=1";
xmlhttp.open("POST", url, true);
xmlhttp.send(params);
它主要调用PHP脚本,然后PHP脚本将一些信息添加到数据库中。
https://stackoverflow.com/questions/4276226
复制相似问题