1

我正在尝试对与我的 javascript 位于同一文件夹中的 php 页面进行 AJAX 调用(POST)。我http.status = 0越来越http.readyState = 4

这是js代码:

var http = new XMLHttpRequest();
var url = "processor.php";
var params = "processad=ipsum&name=binny";
http.open("POST", url, true);

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.
  alert("status: " + http.status);
  alert("ready state: " + http.readyState);
  if(http.readyState == 4 && http.status == 200) {
    alert(http.responseText);
  }
}
http.send(params);

这是php代码

if (isset($_POST['processad'])) {

    echo "reads";

}

我可以弄清楚这里出了什么问题。两个文件(js 和 php)都在同一个文件夹中,并且 php 文件的路径是相对的。不知道我做错了什么。提前致谢!

添加:

HTTP request looks like this
Request URL:http://as.cbothemes.com/ads_script/processor.php
Request Headersview source
Cache-Control:no-cache
Content-type:application/x-www-form-urlencoded
Origin:http://as.cbothemes.com
Pragma:no-cache
Referer:http:_/_/_as.cbothemes.com/ads_script/12.html?i=100&j=12&cb=1367948759088
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31
Form Dataview sourceview URL encoded
processad:ipsum
name:binny
4

1 回答 1

-1

因为我在这里找不到帮助,所以我只是将 javascript ajax 调用转移到 jQuery。所以这是我不喜欢的解决方案,但它有效。

于 2013-05-09T09:26:22.300 回答