Javascript 从Ajax调用获取响应
当试图从普通javascript中构建的ajax调用中获取responseText时,Firebug似乎看到了请求,但无法获取对responseText的引用 这是函数的代码Javascript 从Ajax调用获取响应,javascript,ajax,Javascript,Ajax,当试图从普通javascript中构建的ajax调用中获取responseText时,Firebug似乎看到了请求,但无法获取对responseText的引用 这是函数的代码 function getAjaxResponse(){ var ajaxObj = getAjaxObj(); ajaxObj.open('get', 'responsePage.php', true); ajaxObj.onReadyStateChanged = function(){
function getAjaxResponse(){
var ajaxObj = getAjaxObj();
ajaxObj.open('get', 'responsePage.php', true);
ajaxObj.onReadyStateChanged = function(){
if(ajaxObj.readyState == 4
&& ajaxObj.status == 200){
//no functions are getting fired in here
//this does not get logged to console
console.log(ajaxObj.responseText);
//neither does this
console.log(2);
}
};
ajaxObj.send(null);
//this does gets logged to console
console.log(1);
}
用于ajax对象的函数
function getAjaxObj(){
var req;
if(window.XMLHttpRequest){
try{
req = new XMLHttpRequest();
} catch(e){
req = false;
} finally {
return req;
}
} else {
if(window.ActiveXObject){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e){
try{
req = new ActiveXObject("Msxml.XMLHTTP");
} catch(e){
req = false;
} finally {
return req;
}
}
}
}
}
这里还有firebug的视图
如何从ajax调用获取响应的引用?
onreadystatechange
需要是onreadystatechange
。JavaScript区分大小写。onreadystatechange
需要是onreadystatechange
。JavaScript是区分大小写的。onreadystatechange
都应该是小写的(并且没有尾随的'd')ajaxObj.onreadystatechange
:onreadystatechange
都应该是小写的(并且没有尾随的'd')哈哈。。非常感谢你,我已经康复了#$#D我会尽快接受你的回答!cheers@user866190很乐意帮忙!哈哈。。非常感谢你,我已经康复了#$#D我会尽快接受你的回答!cheers@user866190很乐意帮忙!看一看:看一看: