javascript Phantom JS 同步 AJAX 请求:NETWORK_ERR:XMLHttpRequest 异常 101
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15913170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Phantom JS synchronous AJAX request : NETWORK_ERR: XMLHttpRequest Exception 101
提问by sublime
I am making a synchronous ajax call ( ajax settings async: false ). This works well.
我正在进行同步 ajax 调用( ajax settings async: false )。这很好用。
Now I'm trying to write an automated test for this in phantomJS and I'm getting this error
现在我正在尝试在 phantomJS 中为此编写一个自动化测试,但出现此错误
NETWORK_ERR: XMLHttpRequest Exception 101
I checked my service logs and it seems like service is not getting any request.
我检查了我的服务日志,似乎服务没有收到任何请求。
回答by johnnycrab
Try disabling the web security by using the command-line option --web-security=no
when running your script. (phantomjs --web-security=no yourscript.js
)
尝试--web-security=no
在运行脚本时使用命令行选项禁用网络安全。( phantomjs --web-security=no yourscript.js
)
From the PhantomJS reference (http://phantomjs.org/api/command-line.html):
从 PhantomJS 参考(http://phantomjs.org/api/command-line.html):
"--web-security=[true|false]
enables web security and forbids cross-domain XHR (default is true). Also accepted: [yes|no]
"--web-security=[true|false]
启用网络安全并禁止跨域 XHR(默认为 true)。也接受:[yes|no]