我一直在学习AJAX,我对AJAX调用中的方法执行顺序有点困惑。我看到了太多的变化。例如在AJAX调用中首先执行哪些方法?
function submitArticle() {
try {
//alert("yaay");
xhr = new XMLHttpRequest();
}
catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
alert("Your Browser is not Supported");
return false;
}
}
}
var parameters = "postTitle=" + postTitle "&postDes=" + postDes + "&postCont=" + postDes;
xhr.open('POST', '/engine/engine.php', true);
xhr.send(parameters);
xhr.onreadystatechange = function() {
if(this.readyState === 4) {
if(this.status ===200) {
alert(this.responseText);
}
else {
alert("status" + this.status);
}
}
else {
alert("readyState" + this.readyState);
}
}
}
我的问题是,我所看到的代码,其中开放和发送方法被放置在一个非常不同的部位,如评估readyState值为后。这是正确的路要走。我已经在不同的网站上查看它,所有我看到的都是jQuery教程,并且他们都没有解释代码将以何种顺序执行。对不起,如果这是一个非常愚蠢的问题,或者如果我的代码是错误的。
该代码不正确。什么是open()和send()。它缺少'xhr.' – epascarello
谢谢,生病就此做出改变。 – Bazinga777