Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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 当出现“时,无法捕获错误”;reqwest“;java脚本中的调用失败_Javascript_Xmlhttprequest_Es6 Promise_Reqwest - Fatal编程技术网

Javascript 当出现“时,无法捕获错误”;reqwest“;java脚本中的调用失败

Javascript 当出现“时,无法捕获错误”;reqwest“;java脚本中的调用失败,javascript,xmlhttprequest,es6-promise,reqwest,Javascript,Xmlhttprequest,Es6 Promise,Reqwest,我正在使用“reqwest”进行rest呼叫服务。我对打电话时发生的错误感兴趣。这是我的简单例子 <!doctype html> <html> <body> <script src="node_modules/es6-promise/dist/es6-promise.js"></script> <script src="node_modules/reqwest/reqwest.js"></script> <

我正在使用“reqwest”进行rest呼叫服务。我对打电话时发生的错误感兴趣。这是我的简单例子

<!doctype html>
<html>
<body>
<script src="node_modules/es6-promise/dist/es6-promise.js"></script>
<script src="node_modules/reqwest/reqwest.js"></script>
<script src="src/js/test.js"></script>

</body>
</html>
以下错误显示在我的控制台上

XMLHttpRequest cannot load http://www.google.com/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 405.

我想捕获此信息,但失败时回调函数在err param中未捕获此信息。它是空的XMLHTTPRequest。我确信它没有任何其他参数。请求永远不能为空。我做错了什么。

这似乎是CORS的问题。您正在使用XHR从另一个源(域)请求数据,而不是从您的站点最初加载的源(域)。您将永远看不到此类请求中的内容——出于安全原因,浏览器会阻止这些请求。在这里读更多:我同意你的观点。我无法用java脚本捕获这些信息?至少我怎么知道哪一个脚本和哪一行负责打印这一行?我试着在脚本中添加断点,看起来像是调用promise上的默认try-catch方法。嗯。。。我看到了问题所在,并在这里进行了复制。奇怪的是,错误发生后,XHR对象不包含关于failure.ya的任何信息。考虑到图书馆的受欢迎程度,应该有人报告它。我想我要找的是基本的。虽然我对JS的了解有限,但看起来像这里报道的某个人
XMLHttpRequest cannot load http://www.google.com/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 405.