1
我想做一個AJAX調用(POST)到與我的JavaScript相同的文件夾中的PHP頁面。我越來越http.status = 0
和http.readyState = 4
HTTP響應0從Javascript的Ajax調用
這是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
所以你真的看看http流量?它是什麼樣子的? – eis 2013-05-07 18:28:31
這段代碼何時被調用?點擊一個按鈕?該按鈕是否也提交表單?一個錨點被點擊?錨點是否仍然導航頁面? – Ian 2013-05-07 18:42:42
我添加了http請求。代碼被手動調用(用JS代碼打開html頁面) – user2331875 2013-05-07 19:20:48