Php receives ajaxpost data encoding only for gb2312

Source: Internet
Author: User
Ladies and gentlemen, I am a beginner. I used the ajaxpost login module to submit data to php. I found that I could normally receive data using gb2312 encoding, and I didn't respond to it using UTF-8 encoding for php. My web pages are all UTF-8 encoded. why? After gb2312 is used, the server can query the database normally. However, after '1' is returned, if and '1' in the js code are not equal, and the result enters the else code, is the encoding format different? Thank you! The js code is as follows: functionloginphp () {xmlhttp. onread... phppost

Ladies and gentlemen, I am a beginner. I used the ajax post login module to submit data to php and found that the data can be normally received using gb2312 encoding, php end encoded with UTF-8 has no response. My web pages are all UTF-8 encoded. why? After gb2312 is used, the server can query the database normally. However, after '1' is returned, if and '1' in the js code are not equal, and the result enters the else code, is the encoding format different? Thank you!
The js code is as follows: function loginphp (){

Xmlhttp. onreadystatechange = function () {if (xmlhttp. readyState = 4 & xmlhttp. status = 200) {msg = xmlhttp. responseText; if (msg = '1') {document. getElementById ("login "). innerHTML = "logon successful! ";} Else if (msg = '2') {document. getElementById (" login "). innerHTML =" incorrect user name or password! ";}Else {document. getElementById (" login "). innerHTML = msg ;}}

}
Xmlhttp. open ("POST", "application/reglog/login. php", true );
// XmlHttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded; charset = utf-8 ");

Xmlhttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded; charset = gb2312 ");
Xmlhttp. send ("email =" + $ ('email '). value + "& pwd =" + $ ('pwd'). value );
}

The php code is as follows:
Include_once "dbconn. php ";
$ SQL = "select * from Basicinfo_user where user_email = '". $ _ POST ['email ']. "'and user_password = '". $ _ POST ['pwd']. "'";
$ Num = $ conne-> getRowsNum ($ SQL );
$ Conne-> close_conn ();
If ($ num = 1 ){
Echo '1 ';
} Else if ($ num = 0 ){
Echo '2 ';
} Else {
Echo $ conne-> msg_error ();
}
?>

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.