I encountered the encoding problem when I used php + Ajax to verify the user name. I encountered this problem while testing the code. The code is as follows: index. php & lt; script & nbsp; type = "text/javascript" & nbsp; src = "ajax. js "& gt; & lt;/script & gt; & nbsp; & l php + Ajax encoding problems encountered when verifying the user name
I encountered this problem when testing the code.
The code is as follows:
Index. php
《script》
;
Ajax. js
var xmlHttp;
function S_xmlhttprequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function funphp100(name) {
var f=document.myform.user.value;
S_xmlhttprequest();
xmlHttp.open("GET","for.php?id="+f,true);
xmlHttp.onreadystatechange = byphp;
xmlHttp.send(null);
}
function byphp() {
if(xmlHttp.readyState == 1) {
document.getElementById('php100').innerHTML = "";
}
if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
var byphp100 = xmlHttp.responseText;
document.getElementById('php100').innerHTML = byphp100;
}
}
}
For. php
If (@ $ _ GET [id]) {
Sleep (1 );
$ Conn = mysql_connect ('localhost', 'root ','');
Mysql_select_db ('test', $ conn );
Echo $ SQL = "SELECT * FROM 'user' where 'user' = '$ _ GET [id]'";
$ Q = mysql_query ($ SQL );
If (is_array (mysql_fetch_row ($ q ))){
Echo "the user name already exists ";
} Else
{
Echo "available ";
}
}
?>
I tested both the local environment and the BAE environment.
There is a phenomenon that Chinese characters cannot be transmitted normally. the database already has a "Thousand Hands" user, but it still prompts you to use this user, which seems to be a problem of encoding.
, Ask someone else to answer ~ PHP Ajax MySQL test: script?... 'Data-pics = ''>
------ Solution --------------------
F = encodeURI (f); forgot to assign a value! Try it!
------ Solution --------------------
It is likely that the problem of database encoding is:
show variables like 'char%'
I guess it's GBK.