问题:XMLHttpRequest - 处理服务器连接丢失 [英] Problem: XMLHttpRequest - handle server connection lost
本文介绍了问题:XMLHttpRequest - 处理服务器连接丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用XMLHttpRequest向服务器发出同步请求而服务器不可用的情况如何处理?
How do I handle the scenario where I making a synchronous request to the server using XMLHttpRequest and the server is not available?
xmlhttp.open("POST","Page.aspx",false);
xmlhttp.send(null);
现在这种情况会导致 JavaScript 错误:系统找不到指定的资源"
Right now this scenario results into a JavaScript error: "The system cannot locate the resource specified"
推荐答案
好的,我用 try...catch around xmlhttprequest.send 解决了
Ok I resolved it by using try...catch around xmlhttprequest.send
:
xmlhttp.open("POST","Page.aspx",false);
try
{
xmlhttp.send(null);
}
catch(e)
{
alert('there was a problem communicating with the server');
}
这篇关于问题:XMLHttpRequest - 处理服务器连接丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文