首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ajax崩溃IE 7

Ajax崩溃IE 7
EN

Stack Overflow用户
提问于 2012-05-12 12:06:51
回答 1查看 225关注 0票数 1

这是我的ajax代码

代码语言:javascript
复制
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字符串。

EN

回答 1

Stack Overflow用户

发布于 2012-05-12 12:22:44

试试这个函数--它是一个little more robust,而不是你正在使用的。

代码语言:javascript
复制
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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10561003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档