使用ajax来给用户名做验证时,出现了请求数次后就没有反应了,为什么? 求大神们解决 . 谢了!
$(function(){ $("#username").blur(function(){ var name=$(this).val(); var time=new Date().getTime(); $.ajax({ type:"get", url: "CheckUserName?name="+name+"&time="+time, cache: false,// 设置浏览器不缓存页面 async: true,// 所有的请求都是异步的 默认就是 dataType: "json", success:function(result){ // 为true 代表用户名为空 表示可用 alert(result); } }) }) })
<input type="text" name="username" id="username" style="width: 160px;" />
我是这么写的,我试了八次左右以后,就弹不出来了 ? 求各位大神解决 ?
直接访问CheckUserName?name="+name+"&time="+time 地址试试有错误吗?
[code="javascript"]
$(function(){
$("#username").blur(function(){
var name=$(this).val();
var time=new Date().getTime();
$.ajax({
type: "POST",
url: "CheckUserName?name="+name+"&time="+time,
cache: false,// 设置浏览器不缓存页面
async: true,// 所有的请求都是异步的 默认就是
dataType: "json",
success: function(result)
{
// 为true 代表用户名为空 表示可用
alert(result);
},
error : function()
{
alert("系统出现问题");
}
})
})
})
[/code]
用的是jquery吗,用最新版 试试呢,用不同的浏览器试试呢?
没有在浏览器上看看请求么,或者在后台加断点,单步调试看看
调用的方法及原理你搞清楚了么? contextpath的概念清楚么?这个是我封装的例子,你可以参考下[code="js"]
var url = '<%=request.getContextPath()%>'+'/request_resources';
var doc= callAjax(url,'GET','xml');
/**
[/code]