如何在 Safari 中允许跨域请求?
我有从 localhost 运行的 webapp(因为调试),它发出跨域 AJAX 请求.我可以轻松地为 Chrome--disable-web-security"设置标志,并且 webapp 在 Chrome 中按预期工作.但我也需要为 Windows 上的 Safari 执行此操作.是否有一些类似的标志或者我可以在 Preferences 的某个地方设置它?
I have webapp I run from localhost (because of debugging) and it makes cross-domain AJAX requests. I can easily set flag for Chrome "--disable-web-security" and the webapp works as expected in Chrome. But I need to do this for Safari on Windows as well. Is there some similar flag or can I set this in Preferences somewhere ?
感谢您的帮助.
推荐答案
解决办法是在服务器上设置一个header Access-Control-Allow-Origin: *
.
Solution is to set a header Access-Control-Allow-Origin: *
on the server.
在 PHP 中很简单:
In PHP it's easy like this:
header("Access-Control-Allow-Origin: *");
将答案归功于 Brain2000,感谢您在评论中提出链接.
Credit for the answer goes to Brain2000, thanks for suggesting a link in your comment.
相关文章