problem using AJAX call in IE6 and IE7 — I am asking the same question again, cause i did not get any solution before

梦想与她 提交于 2019-12-08 05:36:08

问题


I have this code, which is working fine in FireFox, chrome and IE8 but is it not working on IE6 and IE7.

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;
}

function login()
{
    alert("Entered Login()");   
    var url="http://server.com/ALUauth.php";
    xmlhttp.onreadystatechange=statechangedLogin;
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}

function statechangedLogin()
{
    if(xmlhttp.readyState==4)
    {
        alert("Entered State Changed Login");
        if (xmlhttp.responseText=="Please <a href=http://server.com/ALUauth.php?login>login</a>")
        {
                document.getElementById("ALUauth").innerHTML=xmlhttp.responseText;
        }
        else
        {
                GetEmailId();
        }

    }
}

function GetEmailId()
{   
    alert("Entered 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)
    {
        alert("Enter State Changed Login 2");
        if(xmlhttp.responseText=="Login again")
        {
                window.location="http://server.com/profile.html";
        }
    }
}

When I run the code in any other browser except for IE6 and 7 the output shows me all the alert boxes starting from: - Entered Login() - Entered State Changed Login - Entered GetEmailId() - Enter State Changed Login 2

and then the window location changes to http://server.com/profile.html

but when I run the same thing on IE 6 or 7, the code does not go into the statechangedLogin2(), and so the only alerts I get here are:

* Entered Login()
* Entered State Changed Login
* Entered GetEmailId()

I am unable to figure out why this issue is occuring. Why is it happening, and what should I change? The project is working absolutely fine on other browsers include IE8.

Can some one help me figure this issue of mine.


回答1:


Hello i am sorry to post my question again. but i was not getting any solution there so i tried to do this. thou i am sorry about it.

Anyways i was able to solve the situation with the help of my boss.

all i did was to give GetEmailId function its own session. something like this:

function GetEmailId()

{ alert("Entered GetEmailId()"); xmlhttpTwo=GetXmlHttpObject() var url="http://server.com/GetPostEmail.php"; url=url+"&sid="+Math.random(); xmlhttpTwo.onreadystatechange=statechangedLogin2; xmlhttpTwo.open("GET", url, true); xmlhttpTwo.send(null); }

I tried this and it works absolutely fine on IE 6 n 7 ... :)

Best Zeeshan




回答2:


Can you use JQuery, Prototype, Ext JS Base, or one of the other freely-available Javascript frameworks to do this instead?

There are a huge number of little browser inconsistencies to work around, so I don't recommend re-inventing the wheel--I know, I've done it before.



来源:https://stackoverflow.com/questions/1229821/problem-using-ajax-call-in-ie6-and-ie7-i-am-asking-the-same-question-again-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!