用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 ";
}
}
?>
老出现乱码
/*
* 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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28