跨域AJAX失败,即使是本地文件 [英] Cross domain ajax fails even for a local file

查看:154
本文介绍了跨域AJAX失败,即使是本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地 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

这篇关于跨域AJAX失败,即使是本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆