关于jQuery超时错误处理
最近,我发现一些关于超时的错误。
请看下面的代码。
- jQuery 超时:5000 毫秒
- Servlet 睡眠:10000 毫秒
客户端 Javascript
$.ajaxSetup({
url: "http://localhost:8888/{mydomain}",
timeout : 5000,
error:function (xhr, textStatus, thrownError){
switch(xhr.status) {
case 0 :
$('#msg').append("0");
break;
case 404:
$('#msg').append("404 ERROR.");
break;
case 500:
$('#msg').append("500 ERROR.");
break;
case 408:
$('#msg').append("408 ERROR.");
break;
default :
$('#msg').append(xhr.status);
break;
}
}
});
$(function() {
$.ajax({
type: "GET",
dataType:"JSON",
data:{send a some data},
success:function(response){
alert(response);
}
})
});
Java 进程
@Path("/{mydomain}")
public class DummyResource {
@GET
@Produces(MediaType.TEXT_HTML)
public String getMethod() throws Exception {
try {
Thread.sleep(10000);
} catch(InterruptedException ie) {
throw new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE);
}
return "hello!";
}
}
但是,Safari 和 Firefox 之间的错误是不同的。
Safari(超时错误:我认为,这个结果是正确的。)
<前><代码>> GET //localhost:8888/{mydomain} 已中止Firefox(成功,但发生了一些错误)
<前><代码>> GET //localhost:8888/{mydomain} 200 OK 10.01s 未捕获的异常:[异常...“组件返回失败代码:0x80040111(NS_ERROR_NOT_AVAILABLE)[nsIXMLHttpRequest.status]”nsresult:“0x80040111(NS_ERROR_NOT_AVAILABLE)”位置:“JS框架:://localhost:8888/{mydomain}/ajax .html :: 匿名 :: 第 20 行数据:否]
我的系统信息
MacOSX : 10.6.5
浏览器:Safari 5.0.3、火狐 3.6.8
Recently, I found some error about timeout.
Please see below code.
- jQuery timeout : 5000 ms
- Servlet sleep : 10000 ms
Client side Javascript
$.ajaxSetup({
url: "http://localhost:8888/{mydomain}",
timeout : 5000,
error:function (xhr, textStatus, thrownError){
switch(xhr.status) {
case 0 :
$('#msg').append("0");
break;
case 404:
$('#msg').append("404 ERROR.");
break;
case 500:
$('#msg').append("500 ERROR.");
break;
case 408:
$('#msg').append("408 ERROR.");
break;
default :
$('#msg').append(xhr.status);
break;
}
}
});
$(function() {
$.ajax({
type: "GET",
dataType:"JSON",
data:{send a some data},
success:function(response){
alert(response);
}
})
});
Java process
@Path("/{mydomain}")
public class DummyResource {
@GET
@Produces(MediaType.TEXT_HTML)
public String getMethod() throws Exception {
try {
Thread.sleep(10000);
} catch(InterruptedException ie) {
throw new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE);
}
return "hello!";
}
}
But, error is different between Safari and Firefox.
Safari (timeout error: I think, this result is right.)
> GET //localhost:8888/{mydomain} Aborted
Firefox(success, but some error occured)
> GET //localhost:8888/{mydomain} 200 OK 10.01s uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: //localhost:8888/{mydomain}/ajax.html :: anonymous :: line 20" data: no]
My System Info
MacOSX : 10.6.5
Browser: Safari 5.0.3, Firefox 3.6.8
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论