21,891
社区成员
发帖
与我相关
我的任务
分享
var xmlHttp;
function createAJAX(){
try{
xmlHttp = new XMLHttpRequest();
} catch(e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
alert("您的浏览器不支持AJAX!");
return;
}
}
}
}
function usernamecheck(){
str=document.userinfo.username.value;
var url="userquery.php?str="+str;
if(str.length!=0){
createAJAX();
xmlHttp.onreadystatechange=query;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}else{
document.getElementById("checkusername").innerText="";
}
}
function query(){
if (xmlHttp.readyState == 4 ){
if (xmlHttp.status==200)
{
if (xmlHttp.responseText=="true"){
document.getElementById("checkusername").innerText="该帐号已被占用";
//document.getElementById("checkusername").innerText=xmlHttp.responseText;
document.all.isadd.value="true";
}else {
document.getElementById("checkusername").innerText="该帐号可用";
document.all.isadd.value="false";
}
}
}
}
$conn=mysql_connect('localhost','root','root');
mysql_select_db('shop', $conn);
$str=$_GET["str"];
$sql="select * from userinfo where username='$str' ";
$result=mysql_query($sql);
if(mysql_num_rows($result)==0){
echo "false";
}else{
echo "true";
}
mb_internal_encoding("gb2312"); // 转变gb2312编码
mb_http_output("HTML-ENTITIES");
ob_start('mb_output_handler');
$conn=mysql_connect('localhost','root','root');
mysql_select_db('shop', $conn);
//注意数据库编码集应为GBK
//mysql_query("SET NAMES 'GBK'");
$str=$_GET["str"];
$sql="select * from userinfo where username='$str' ";
$result=mysql_query($sql);
if(mysql_num_rows($result)==0){
echo "false";
}else{
echo "true";
}
header('Content-type:text/html;charset=gb2312');
$conn=mysql_connect('localhost','root','root');
mysql_select_db('shop', $conn);
$str=$_GET["str"];
$sql="select * from userinfo where username='$str' ";
$result=mysql_query($sql);
if(mysql_num_rows($result)==0){
echo "false";
}else{
echo "true";
}
$conn=mysql_connect('localhost','root','root');
mysql_select_db('shop', $conn);
$str=$_GET["str"];
$sql="select * from userinfo where username='$str' ";
$result=mysql_query($sql);
if(mysql_num_rows($result)==0){
echo "false";
}else{
echo "true";
}
<script type="text/javascript">
var xmlHttp;
function createAJAX()
{
xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function usernamecheck(str) {
xmlHttp=createAJAX();
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}
var url="userquery.php?str="+str;
xmlHttp.onreadystatechange=query;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function query(){
if (xmlHttp.readyState == 4 ){
if (xmlHttp.status==200){
if (xmlHttp.responseText=="true"){
document.getElementById("checkusername").innerHTML="该帐号已被占用";
//document.getElementById("checkusername").innerText=xmlHttp.responseText;
document.all.isadd.value="true";
}else {
document.getElementById("checkusername").innerHTML="该帐号可用";
document.all.isadd.value="false";
}
}
}
}
</script>
<div>
<input type="text" name="username" class="inputtext" size="25" onblur="usernamecheck(this.value);">
<div>
<div id="checkusername"></div>
header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
header("Pragma: no-cache"); /* 与HTTP1.0兼容 */
function query(){
if (xmlHttp.readyState == 4 ){
if (xmlHttp.status==200)
{
if (decodeURIComponent(xmlHttp.responseText)=="true"){
document.getElementById("checkusername").innerText="该帐号已被占用";
//document.getElementById("checkusername").innerText=xmlHttp.responseText;
document.all.isadd.value="true";
}else {
document.getElementById("checkusername").innerText="该帐号可用";
document.all.isadd.value="false";
}
}
}
}