gpt4 book ai didi

ajax - canary --disable-web-security 不再适用于 AngularJS 项目中的 ajax 请求

转载 作者:行者123 更新时间:2023-12-04 22:11:55 25 4
gpt4 key购买 nike

在本地主机上开发时,使用参数启动金丝雀 --disable-web-security 不再有助于发送跨域 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 请求设置 header ?

P. S. 我使用别名以所需的参数启动金丝雀
alias canary="open -a \"Google Chrome Canary\" --args --disable-web-security"

最佳答案

编辑

工作解决方案:使用命令 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

关于ajax - canary --disable-web-security 不再适用于 AngularJS 项目中的 ajax 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27787474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com