对于AngularJS项目中的ajax请求,canary --disable-web-security不再起作用了

时间:2015-01-05 20:36:00

标签: ajax angularjs security google-chrome cross-domain

在localhost上开发时,使用参数--disable-web-security启动canary不再有助于发送跨域AJAX请求

我在控制台中看到一条消息

XMLHttpRequest cannot load http://[some-domain-name].com. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:3100' is therefore not allowed access.

如何在AngularJS项目中为ajax请求设置标头?

P上。 S.我使用别名来启动带有必需args的canary

alias canary="open -a \"Google Chrome Canary\" --args --disable-web-security"

2 个答案:

答案 0 :(得分:13)

修改

工作解决方案:使用命令open -a Google\ Chrome\ Canary --args --disable-web-security --user-data-dir=$HOME/profile-folder-name

说明:--disable-web-security现在需要使用--user-data-dir标志。

Windows命令:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir=%USERPROFILE%\profile-folder-name

这似乎只是Canary中的一个错误(在最新稳定的Chrome中可以正常工作)。 Chrome会看到该标志并显示警告但无法允许跨域请求。它几天前确实有效。

我报告了这个问题:https://code.google.com/p/chromium/issues/detail?id=575690

答案 1 :(得分:0)

尝试关闭浏览器并再次使用特殊参数打开它。

Canary经常更新,当您接受更新它时,它会重新启动而不需要特殊参数。