ajax现已应用到各个网站中。最常见的如会员注册这块,实现快捷。用户体验良好,blog插件添加过了,注册界面可以直接预览html文件。其实主要在于XMLHttpRequest对象读取也替换页面来实现的。对于asp/php或其他环境方法都是一致的,功能就是查库告诉js中,是不是有存在的数据。
用户注册username=Replace(request.querystring("username"),"'","")
sql="select id from puser where y_username='"&username&"'"
rs.open sql,conn,1,1
if rs.eof then
response.write "no"
else
response.write "yes"
end if
rs.close
%>
PHP接口文件命名为:zhoz_checklogin.php 并修改上面的js中的内容
$conn = mysql_connect("localhost", "root", "123456");
$user = $_GET["username"];
$querySQL = "SELECT * FROM users WHERE name = '".$user."'";
mysql_select_db("users", $conn);
$rs = mysql_query($querySQL, $conn);
$rs_cnt = mysql_num_rows($rs);
if($rs_cnt > 0) {
echo "yes";
} else if($rs_cnt==0) {
echo "no";
} else {
echo "error";
?>