+ -
当前位置:首页 → 问答吧 → 用ajax做用户名验证时老出现乱码

用ajax做用户名验证时老出现乱码

时间:2010-09-17

来源:互联网

ajax.php页面<?php
/*
* Created on 2010-9-17
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
?>

<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>验证用户名</title>
</head>
<script language="JavaScript" type="text/javascript">
var xmlHttp;
function S_xmlhttprequest(){
       if(window.ActiveXObject){
       xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
       }else if(window.XMLHttpRequest){
       xmlHttp = new XMLHttpRequest();
       }
}
function funphp100(){
     var f = document.myfrom.username.value;
     //alert(f);
     S_xmlhttprequest();
     xmlHttp.open("GET","for.php?username="+f,true);
     xmlHttp.onreadystatechange = php;
     xmlHttp.send(null);
}
function php(){
     if(xmlHttp.readyState==1){
     document.getElementById('php100').innerHTML = "loading........";
     }
     if(xmlHttp.readyState==4){
        if(xmlHttp.Status==200){
      var byphp = xmlHttp.responseText;
      document.getElementById('php100').innerHTML = byphp;
     }
     }

}
</script>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">

  <form action="" method="post" name="myfrom">

用户名: <input type="text" name="username" value="" onblur="funphp100('p')"/>
       <div id="php100"></div>

  </form>

</body>
</html>

for.php页面

<?php
/*
* Created on 2010-9-7
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
// if($id=$_GET['id']){
//     for($i=1;$i<4;$i++){
//         echo $id;
//         sleep(1);
//     }
//         //exit();
//
// }
//include("conn.php");
if($_GET[username]){
    sleep(1);
$conn=mysql_connect("localhost","root","root")or die("数据库服务器没有连接".mysql_error());
mysql_select_db("tested",$conn);
mysql_query("set names gb2312");
$sql="select * from username where username='$_GET[username]'";
$query=mysql_query($sql);
if(is_array(mysql_fetch_row($query))){
    //echo "<script>alert('您还没有注册,请先注册在登录');</script>";
    echo "yi jing cun zai已经存在 ";
}else{
    echo "ke yi shi yong  ";
}
}
?>
老出现乱码

作者: haolijunphp   发布时间: 2010-09-17

编码问题,Ajax要用UTF-8

作者: jingyexing   发布时间: 2010-09-17

相关阅读 更多

热门下载

更多