0
我有一个问题,我的AJAX代码没有通过onreadtstate。 if(XMLHttpRequestObject)工作正常,但其他部分没有。代码如下:AJAX问题 - onreadystate不起作用
enter code here function
//Get the Ajax Object
getXmlHttpRequestObject() {
if (window.XMLHttpRequest && !(window.ActiveXObject)) {
XMLHttpRequestObject= new XMLHttpRequest();
return XMLHttpRequestObject;
}
else if (window.ActiveXObject) {
try{
XMLHttpRequestObject=new ActiveXObject("Msxml2.XMLHTTP");
return XMLHttpRequestObject;
}catch(exception1){
try{
XMLHttpRequestObject= new ActiveXObject("Microsoft.XMLHTTP");
return XMLHttpRequestObject;
}catch(exception2){
}//end exception 2
}//end exception 1
}//end if else
else{
document.getElementById('ajax_status').innerHTML='Status: Cound not create XmlHttpRequest Object.' +
'Consider upgrading your browser.';
}
}//end function getXmlHttpRequestObject() {
function loadJavascript(src, url){
XMLHttpRequestObject=getXmlHttpRequestObject();
if(XMLHttpRequestObject){
//an alert will work here
XMLHttpRequestObject.onreadystatechange = function()
{
alert("Here");
//Nothing at this pint works
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
includeJavaScript(sId, url, oXmlHttp.responseText);
}
}
}
}//end LoadJavaScript
有没有人有什么可以出错的想法?
@Matti是对的。另外考虑使用第三方JavaScript库,如jQuery或Prototype。编写浏览器特定的代码已经过去了,这些库将为您提供最好完全独立于浏览器的编程接口。 – themoondothshine 2010-04-04 15:24:29