duanpie2834 2011-11-02 14:54
浏览 85
已采纳

在IE6中创建XMLHTTPRequest

I am applying the following Javascript in a check form function:-

var msg1="";
function check_si_form_info(form,mark,edit){

     if(mark==10 || mark=="all"){
     if(form.email.value==""){
       si_check_email.innerHTML="";
       si_check_email.style.height="0px";
       form.email.style.backgroundColor="#FFFFFF";
     }else{ 
       var i=form.email.value.indexOf("@");
       var j=form.email.value.indexOf(".");
       if((i<0)||(j<0)){
         si_check_email.innerHTML="The email address format is incorrect!";
         si_check_email.style.height="auto";
         form.email.style.backgroundColor="#FFD5FF";
         return false;                              
       }
     else{
        var email = form.email.value;
            xmlhttp=new XMLHttpRequest(); //HERE!!!!
            xmlhttp.open('get','si/check_si_email.php?email='+email,true);
            xmlhttp.onreadystatechange = function(){
                if(xmlhttp.readyState == 4){
                    if(xmlhttp.status == 200){
                        msg1 = xmlhttp.responseText;
                        if(msg1 == '1'){
                        si_check_email.innerHTML="email address has been used!";
                        si_check_email.style.height="auto";
                        form.email.style.backgroundColor="#FFD5FF";
                        }else if(msg1 == '2'){
                        si_check_email.innerHTML="";
                        si_check_email.style.height="0px";
                        form.email.style.backgroundColor="#FFFFFF";
                        }else if(msg1 == '3'){
                        si_check_email.innerHTML="";
                        si_check_email.style.height="0px";
                        form.email.style.backgroundColor="#FFFFFF";
                        }
                    }//200
                }//4            
            }//onreadystatechange
            xmlhttp.send(null);
            }
            if (msg1 == '1'){
            return false;
            }
     }
    }

   }

In IE 7 or above, the scripts work perfectly well. But in IE6, the browser always mention the "XMLHttpRequest()" is not defined. If I wish to define it, where and what shall I input?? Thanks a lot!

  • 写回答

3条回答 默认 最新

  • doukuanghuan7582 2011-11-02 14:55
    关注

    In IE6 you need to use new ActiveXObject('Microsoft.XMLHTTP') to create the XHR object.

    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest(); // real browsers
    } catch(e) {
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // <=IE6
    }
    

    But you should really use jQuery, it does all the dirty work for you.
    Additionally dropping IE6 support wouldn't be a bad thing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路