php+Ajax进行验证用户名的时候遇到的编码问题
我在测试代码的时候,遇到了这个问题。
代码如下:
index.php
<br /> <script type="text/javascript" src="ajax.js"></script><br /> <form name="myform" action="" method="post" enctype="text/plain"><br /> 用户名:<br /> <input type="text" name="user" value="" onblur="funphp100('php100')"/><br /> <div id="php100"></div><br /> </form><br />;
<br /> <br /> var xmlHttp;<br /> function S_xmlhttprequest() {<br /> if(window.ActiveXObject) {<br /> xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');<br /> } else if(window.XMLHttpRequest) {<br /> xmlHttp = new XMLHttpRequest();<br /> }<br /> }<br /> <br /> function funphp100(name) {<br /> <br /> var f=document.myform.user.value;<br /> S_xmlhttprequest();<br /> xmlHttp.open("GET","for.php?id="+f,true);<br /> xmlHttp.onreadystatechange = byphp;<br /> xmlHttp.send(null);<br /> }<br /> <br /> function byphp() {<br /> <br /> if(xmlHttp.readyState == 1) {<br /> document.getElementById('php100').innerHTML = "<img src='loading.gif' alt=" php+Ajax进行验证用户名的时候遇到的编码有关问题 " >";<br /> }<br /> <br /> if(xmlHttp.readyState == 4 ){<br /> if(xmlHttp.status == 200) {<br /> var byphp100 = xmlHttp.responseText;<br /> document.getElementById('php100').innerHTML = byphp100;<br /> }<br /> }<br /> <br /> <br /> }<br />
<br /> <?php<br /> if(@$_GET[id]){<br /> sleep(1);<br /> $conn=mysql_connect('localhost','root','');<br /> mysql_select_db('test',$conn);<br /> <br /> echo $sql="SELECT * FROM `user` where `user`='$_GET[id]'";<br /> $q=mysql_query($sql);<br /> <br /> if(is_array(mysql_fetch_row($q))){<br /> echo "<font color=red>用户名已经存在</font>";<br /> }else<br /> {<br /> echo "<font color=green>可以使用</font>";<br /> }<br /> }<br /> ?>