問題描述
我有從 localhost 運行的 webapp(因為調試),它發(fā)出跨域 AJAX 請求.我可以輕松地為 Chrome--disable-web-security"設置標志,并且 webapp 在 Chrome 中按預期工作.但我也需要為 Windows 上的 Safari 執(zhí)行此操作.是否有一些類似的標志或者我可以在 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.
這篇關于如何在 Safari 中允許跨域請求?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!