Ajax compatibility issues in Firefox. The program runs normally in IE varxmlHttpfalse; functioncreateXMLHttp () {try {xmlHttpnewXMLHttpRequest ();} catch (trymicrosoft) {try {xmlHttpnewActiveXObject (& quot; msxml2.XML Ajax compatibility problems in Firefox browser, the program runs normally in IE
Var xmlHttp = false;
Function createXMLHttp (){
Try {
XmlHttp = new XMLHttpRequest ();
} Catch (trymicrosoft ){
Try {
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (othermicrosoft ){
Try {
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (failed ){
XmlHttp = false;
}
}
}
If (! XmlHttp ){
Alert ("unable to create XMLHttpRequest object! ");
}
}
Function Ajaxcheck (){
Var num = document. myform. uname. value; // obtain the data of the form.
Var url = "check. php? N = "+ num;
CreateXMLHttp ();
XmlHttp. open ("GET", url, true); // true indicates an asynchronous request.
XmlHttp. onreadystatechange = updatePage;
XmlHttp. send (null );
}
Function updatePage (){
If (xmlHttp. readyState = 4 ){
Var response = xmlHttp. responseText;
If (response = "OK "){
Document. myform. nameerr. value = "√ ";
Return true;
} Else if (response = "no "){
Document. myform. nameerr. value = "× user name occupied ";
Return false;
} Else {
Document. myform. nameerr. value = "Server Error ";
Return false;
}
}
}
The code is as above. I used Ajax to check whether the user name exists. in Firefox, if the English mother name is used, it is normal. if the Chinese name is used, it cannot be determined, why ?????
------ Solution --------------------
The error occurs when Ajaxcheck sends the request, which may be caused by Chinese characters,
You can echo the username on the check. php page to check whether the obtained username is garbled. if it is garbled, use urlencode to handle it.
------ Solution --------------------
Var url = "check. php? N = "+ num;
Url = encodeURI (url );
------ Solution --------------------
On the check. php page, check whether the user name is garbled. if the user name is garbled, use urlencode to handle it.
------ Solution --------------------
Discussion
Reference: What is the database code? What is the script code for registering a page? Are the two consistent ?, Otherwise, use the iconv () function to convert the data character encoding.
In my database, databases, tables, and fields all use gb2312. in check. php, mysql_query ("set character set gb2312") is also added ");