Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
读取Javascript中的错误值_Javascript_Jquery - Fatal编程技术网

读取Javascript中的错误值

读取Javascript中的错误值,javascript,jquery,Javascript,Jquery,我在接收服务器响应的方法中处理if块中的错误。为了测试服务不可用的场景,我关闭了服务器 _onResponse: function (err, res) { if (err){ } 执行警报时(“错误”+err) 我收到 Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the

我在接收服务器响应的方法中处理if块中的错误。为了测试服务不可用的场景,我关闭了服务器

_onResponse: function (err, res) {
   if (err){
 }
执行
警报时(“错误”+err)
我收到

Error: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
    at Request.crossDomainError (http://localhost:9000/index.js:33875:14)
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:9000/index.js:33945:20)
我想读取
错误:

我尝试执行
err.message
,但随后我收到了整个错误消息。 我尝试了
err.name
我只得到了文本
'Error'


如何获取javascript变量中的内容
请求已终止

从响应中,我可以说这不是服务器发送的错误。在对禁用CORS的域执行XHR时,引擎会引发该问题。要捕获此错误,请将
index.js中的XHR代码环绕在
try{}catch(e){}
块中的第33945行。在catch块中,您可以使用
e
变量获取错误


只有当您从目标服务器得到响应时,您的块才会处理错误。

此链接可能会对您有所帮助:-否即使服务器没有响应,流也会在错误if块内移动。