这是我的ajax代码
function sendAjax(send_data,id)
{
var ajaxobj;
alert("After this alert problem occurs!");
if (window.XMLHttpRequest) ajaxobj = new XMLHttpRequest();
else ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
ajaxobj.onreadystatechange=function()
{
if(ajaxobj.readyState==4)
{
if(ajaxobj.responseText.match("confirmPage") != null) document.getElementById(id).innerHTML = ajaxobj.responseText;
else
{
if(id == "FreshContent")
document.getElementById(id).innerHTML = "<a id=\"refreshpage\" onClick=\"siteSelection('select')\">Failed.Click here to Reload!</a>";
else
document.getElementById(id).innerHTML = "<a id=\"refreshpage\" onClick=\"sendAjax(0,'latest_gossip_marquee');\">Failed.Click here to Reload!</a>";
}
}
else document.getElementById(id).innerHTML="Loading....";
}
if(id == "FreshContent") ajaxobj.open("GET","sitexyz.php?"+send_data,true);
else ajaxobj.open("GET","html/xyz.html",true);
ajaxobj.send();
}这里的FreshContent是一个div标签,id.it在opera & firefox中工作,但在我的IE7中崩溃了。为了查看服务器返回的页面是否有效,代码检查返回的页面中是否包含confirmPage字符串。
发布于 2012-05-12 12:22:44
试试这个函数--它是一个little more robust,而不是你正在使用的。
function getHTTPObject() {
var xhr = false;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xhr = false;
}
}
}
return xhr;
}https://stackoverflow.com/questions/10561003
复制相似问题