在客户后台管理系统中,涉及到“客户名”或者“用户名”重复的问题,这个问题可以通过“ajax”来解决

以下:ajax.js文件

// JavaScript Document
var XHR; //定义一个全局对象
function createXHR(){ //首先我们得创建一个XMLHttpRequest对象
if(window.ActiveXObject){//IE的低版本系类
XHR=new ActiveXObject('Microsoft.XMLHTTP');//之前IE垄断了整个浏览器市场,没遵循W3C标准,所以就有了这句代码。。。但IE6之后开始有所改观
}else if(window.XMLHttpRequest){//非IE系列的浏览器,但包括IE7 IE8
XHR=new XMLHttpRequest();
}
}
function checkname(){
var username=document.myform.user.value;
createXHR();
XHR.open("GET","checkname.php?>}

以下是:checkname.php(php程序文件)

<?php
$con=mysql_connect("localhost","root","");
if (!$con){die('Could not connect: ' . mysql_error());}
else { mysql_select_db('liyanlong', $con); }
mysql_query('SET NAMES UTF8');
$name=str_replace(" ","",$_GET["id"]);
$sql="select * from lyl_client where client_name='".$name."'";
//print_r($sql);
$query=mysql_query($sql);
//print_r($sql);
//print_r(mysql_num_rows($query));exit;
if(mysql_num_rows($query)>0){
echo "<font color=red>该客户已存在</font>";
}else{
echo "<font color=green>客户名可以使用</font>";
}
?>

以下是调用程序和js的html文件:profile.html

<form name="form2" action="profile_add.php" method="post">

<table>
<tr>
<td class="right_title_2" colspan="2"><input name="client_name" ></td>

</tr></table></form>件:profile.html

 

 

相关文章: