我在支票表单功能中应用以下Javascript: -
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;
}
}
}
}
在IE 7或更高版本中,脚本运行良好。但是在IE6中,浏览器总是提到“XMLHttpRequest()”没有定义。如果我想定义它,我应该在哪里输入什么?非常感谢!
答案 0 :(得分:5)
在IE6中,您需要使用new ActiveXObject('Microsoft.XMLHTTP')
来创建XHR对象。
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest(); // real browsers
} catch(e) {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // <=IE6
}
但你真的应该使用jQuery,它会为你完成所有肮脏的工作 另外,删除IE6支持也不是件坏事。
答案 1 :(得分:0)
xmlhttp=new XMLHttpRequest();
if(!xmlhttp && typeof ActiveXObject != "undefined"){
try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
}
答案 2 :(得分:0)
在article on AJAX on Wikipedia中,您有一个示例,如何在IE 5,IE 5.5和IE 6中启用对AJAX的支持。示例如下:
/*
Provide the XMLHttpRequest constructor for Internet Explorer 5.x-6.x:
Other browsers (including Internet Explorer 7.x-9.x) do not redefine
XMLHttpRequest if it already exists.
This example is based on findings at:
http://blogs.msdn.com/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx
*/
if (typeof XMLHttpRequest == "undefined")
XMLHttpRequest = function () {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {}
//Microsoft.XMLHTTP points to Msxml2.XMLHTTP and is redundant
throw new Error("This browser does not support XMLHttpRequest.");
};