在IE 6.0和7.0中运行我的项目时出现问题(window.location)?

时间:2009-08-04 13:11:46

标签: ajax internet-explorer

我的项目在Firefox,google chorme和IE 8.0中完美运行

但它无法在IE 6.0或7.0上运行

我意识到它在window.location给出了问题 我将我的代码放在这里以显示我在做什么。

function GetEmailId()
{   
    var url="http://server.com/GetPostEmail.php";
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=statechangedLogin2;
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}
function statechangedLogin2()
{
    if(xmlhttp.readyState==4)
    {
        if(xmlhttp.responseText=="Login again")
        {
            window.location="http://server.com/profile.html";
        }
    }
}

所以这个代码在IE 6和7以外的其他浏览器中运行良好。 当我在xmlhttp.responseText中从我的AJAX获得响应时,它应该转到profile.html,而不是在IE 6和7中,它会保留在我之前的原始页面上,即qotw.html。

我认为window.location有问题,可能我需要一个不同的命令。

此外,我的GetXmlHttpObject看起来像这样。

function GetXmlHttpObject() {
  //var xmlHttp = null;
  try {
    xmlHttp = new XMLHttpRequest();
  } catch (e) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

如果有人能帮助我解决我的这个问题。

此致 zeeshan

注意:我再次尝试解码我​​的代码并意识到在IE 6和7中我的代码永远不会进入statechangedLogin2()。这就是我的代码不起作用的原因。但是为什么会发生这种代码,即使在IE8中它在其他浏览器中运行良好?

1 个答案:

答案 0 :(得分:1)

location属性是一个对象,url是该对象中的href属性。请改用:

window.location.href="http://server.com/profile.html";