跨域AJAX失败,即使是本地文件即使是、本地文件、跨域、AJAX

2023-09-10 16:25:35 作者:Don't pack 回眸一笑

我有一个本地 HTML与AJAX功能试图拉从 x.com XML内容的文件。当运行仅适用于IE和失败的Firefox和Safari浏览器中的文件。 Ofcourse,这可能是因为同样的原产地政策。但是,我已经听到有人说,对于使用文件加载脚本://协议,这个同源策略将不适用。这是真的,如果是,可能是什么问题,我的本地HTML文件?

I have a local html file with an ajax function trying to pull a xml content from x.com. The file when run works only on IE and fails on firefox and safari browsers. Ofcourse this may be because of the Same origin policy. But,I have heard from someone that for scripts loaded using file:// protocol,this same origin policy will not apply. Is it true and if yes, what can be problem with my local html file?

推荐答案

这确实适用于本地文件,把它们全当成单独的域(这由各个浏览器,你所看到的)。例如,在Chrome浏览器,你可以使用命令行启动它允许这样的:

It is indeed applied to local files, treating them all as separate domains (this varies by browser, as you're seeing). For example in Chrome you can launch it with a command line to allow this:

chrome.exe --allow-file-access-from-files