0
我遇到了AJAX問題,其中PHP返回的狀態碼爲0.我在本地域上運行它,並且我不明白爲什麼它不會返回任何內容。它寫跳回到bar.txt,但它什麼都不返回到AJAX請求,狀態代碼爲0。PHP返回狀態0
Ajax請求:
function sendRequestToButler(requestText, callback) {
try {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {if(request.readyState == 4 && request.status == 200) {callback(request);} else {alert("Error: AJAX: readyState: " + request.readyState + " status: " + request.status);}};
request.open("POST", "foo.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", requestText.length);
request.setRequestHeader("Connection", "close");
request.send(request);
} catch(e) {alert("error"); return "CouldNotCompleteRequest";}
}
foo.php:
<?php
file_put_contents('bar.txt', "facepalm", LOCK_EX);
echo "foobar";
?>
好吧,我做到了同步,並以某種方式解決了它,但是不應該在readystate更改時觸發onreadystatechange事件嗎? – enbug 2011-02-15 17:21:53