ajax

<input type="text" id="uid" />
<span id="tishi"></span>

</body>

<script type="text/javascript">

$("#uid").blur(function(){
//取用户名
var uid = $(this).val();
//查数据库,调ajax
$.ajax({
url: "testchuli.php",//处理页面的地址
data:{u:uid}, //要传递的数据(提交
type:"POST", //提交方式
dataType:"TEXT", //返回数据格式
success:function(data){ //回调函数
var str = "";
if(data.trim()=="OK")
{
str = "该用户名可用";
$("#tishi").css("color","green");
}
else
{
str = "该用户名已存在";
$("#tishi").css("color","red");
}
$("#tishi").text(str);
}
});
})

posted @ 2017-01-05 13:51  梦梦梦梦想  阅读(81)  评论(0编辑  收藏  举报