0
我想第一次使用AJAX,并遇到问题。我没有设法通过阅读教程来解决它。AJAX请求不会去readystate 4
我在我的服务器上有一个PHP文件,它在我直接访问文件时回应正确的输出。但是,当我尝试通过HTML访问它。这里是我的javascript代码:
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
httpRequest.open('GET', 'http://www.mysite.com/myfile.php?variable1=' + variable1 + "&variable2=" + variable2, true);
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4) {
var receivedString = httpRequest.responseText;
console.log(receivedString);
} else {
console.log(httpRequest.readyState);
}
};
什么也没有发生;既不receivedString也不输出httpRequest.readyState的值。可能是什么原因?
你在控制台中看到任何问题吗? –
不,在Chrome控制台中没有错误 – user3324865
你在请求对象上的哪个地方调用.send()? – kinakuta