Ajax:Internet Explorer错误

I am working on a login form. The Ajax code is as follows:

/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */

    function createObject() 
    {
    var request_type;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
    request_type = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
    request_type = new XMLHttpRequest();
    }
    return request_type;
    }

    var http = createObject();

    /* -------------------------- */
    /* LOGIN */
    /* -------------------------- */
    /* Required: var nocache is a random number to add to request. This value solve an     Internet Explorer cache issue */
    var nocache = 0;
    function login() {
    // Optional: Show a waiting message in the layer with ID ajax_response
    document.getElementById('login_response').innerHTML = "<img src='images/ispinner.gif'/>"
    // Required: verify that all fileds is not empty. Use encodeURI() to solve some issues    about character encoding.
    var email = encodeURI(document.getElementById('emailLogin').value);
    var psw = encodeURI(document.getElementById('pswLogin').value);
    // Set te random number to add to URL request
    nocache = Math.random();
    // Pass the login variables like URL variable
    http.open('get', 'login.php?email='+email+'&psw='+psw+'&nocache = '+nocache);
    http.onreadystatechange = loginReply;
    if(window.XMLHttpRequest)
    {
    http.send(null);
    }
    else
    {
    http.send()
    }
    }
    function loginReply() {
    if(http.readyState == 4){ 
    var response = http.responseText;
    document.getElementById('login_response').innerHTML = response;
    }
    }

The code works absolutely fine on google chrome and mozilla firefox. It just does not work on IE 5 and IE 6. I cannot figure out why?

Update: Implemented few alert boxes in the code. found out that the execution in Internet explorer does not go beyond

document.getElementById('login_response').innerHTML = "<img src='images/ispinner.gif'/>"

Is there some other syntax to get the form values?

查看全部
weixin_33698823
weixin_33698823
2010/04/09 14:55
  • php
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信

1个回复