weixin_33698823 2010-04-09 14:55 采纳率: 0%
浏览 58

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?

  • 写回答

1条回答 默认 最新

  • weixin_33743248 2010-04-09 15:05
    关注

    You've got some extra spaces around your 'nocache' querystring attribute's "=" sign. Not sure how IE handles those. Probably replaces them with "%20"s, which is not likely the source of your error, but it's malformed nonetheless.

    Could you inspect/debug your JavaScript with the IE Developer Toolbar to make sure all your objects are getting created properly?

    Also see my comment about the request caching. Maybe you had a request cached that returned an empty response so it only appears that it is not working.

    Try putting some alert()'s in your callback function to see if it ever gets there.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab