ajax+php

小工头 2010-08-09 01:39:53
ajax代码:
==========================================================================================================
ajax.js
var xmlHttp;
function creatXMLHttpRequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(id,url) {
creatXMLHttpRequest();
xmlHttp.onreadystatechange = function(){handleStateChange(id);}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function handleStateChange(id) {
if(xmlHttp.readyState == 1) {
document.getElementById(id).innerHTML = "<div class='cs'>正在加载请稍等...</div>";
}
if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
var allcon = xmlHttp.responseText;
document.getElementById(id).innerHTML = allcon;
//alert(allcon);
}
}
}

php代码:
==========================================================================================================
<?php
require_once('include/conn.php');
header('Content-Type:text/html;charset=GBK');
if($_GET['name']!=''){
$uname=$_GET['name'];
sleep(1);
$strsql="SELECT * FROM tb_user WHERE userMobile='$uname'";
$result=mssql_query($strsql);
$rows=@mssql_num_rows($result);
if($rows>0){
echo "<font color=red>"."已被注册!"."</font>";
}else{
echo "<font color=red>"."此用户名未被注册!"."</font>";
}
}else{
echo "<font color=red>"."用户不能为空且为手机号"."</font>";
}
?>

html页面代码:
==========================================================================================================
<input name="userMobile" type="text" id="userMobile" maxlength="11" onblur="startRequest('ajaxcls','eee.php?name='+this.value);"/></td>
...全文
132 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yiyi0724 2010-08-11
  • 打赏
  • 举报
回复
学习!
liangpei2008 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 haoren_shw 的回复:]

没问题。。贴出来学习下。
让高人给点意见 。。
[/Quote]
写得太帅了
natici 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 xuzuning 的回复:]
有一个问题你没有注意!
php 程序里有
header('Content-Type:text/html;charset=GBK');
可知你的页面也是 gbk 的,这样在处理中文时要出问题的
[/Quote]
不是要统一编码吗?为什么要出问题?
Abin-2008 2010-08-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 haoren_shw 的回复:]

没问题。。贴出来学习下。
让高人给点意见 。。
[/Quote]
.........
你今天心情一定很好....
xuzuning 2010-08-09
  • 打赏
  • 举报
回复
有一个问题你没有注意!
php 程序里有
header('Content-Type:text/html;charset=GBK');
可知你的页面也是 gbk 的,这样在处理中文时要出问题的
小工头 2010-08-09
  • 打赏
  • 举报
回复
这个都试过了,IE,火狐,遨游都没什么问题。。。
Dleno 2010-08-09
  • 打赏
  • 举报
回复
那你现在应该测试的是在其他浏览器下能否正常执行??
小工头 2010-08-09
  • 打赏
  • 举报
回复
谢谢。。。。。。
CunningBoy 2010-08-09
  • 打赏
  • 举报
回复
嗯,已阅,不错。
小工头 2010-08-09
  • 打赏
  • 举报
回复
没问题。。贴出来学习下。
让高人给点意见 。。
CunningBoy 2010-08-09
  • 打赏
  • 举报
回复
什么问题?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧