The program runs normally in IE due to issues related to Ajax compatibility in Firefox

Source: Internet
Author: User
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 ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.