"XMLHttpRequest无法加载文件:///...预检响应不成功".错误 [英] "XMLHttpRequest cannot load file:///... Preflight response is not successful" error

查看:296
本文介绍了"XMLHttpRequest无法加载文件:///...预检响应不成功".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个网站,并且该页面使用Jquery .load()函数加载了导航栏和其他资源(如下面的代码所示).

I'm building a website and the page loads a navbar and some other resources with Jquery .load() function (as seen in code below).

<script>
        $(function () {
            $("#navbar-placeholder").load("subpage_navbar.html");
        });
</script>

在safari 5中在计算机上本地查看.html文件时,一切正常,并且过去在safari 11中工作正常,但是现在当我尝试打开文件时,出现错误:

When viewing the .html files locally on my computer in safari 5 everything works fine, and it used to work fine in safari 11, but now when I try to open the file I get an error:

XMLHttpRequest无法加载文件:///...预检响应不成功

XMLHttpRequest cannot load file:///... Preflight response is not successful

我需要在野生动物园中更改任何偏好设置才能使其像以前一样工作吗?

Are there any preferences I need to change in safari for this to work like it used to?

推荐答案

XMLHttpRequest不适用于仅使用http,数据,chrome,chrome扩展名,https的文件协议.

XMLHttpRequest dont work with file protocol only with http, data, chrome, chrome-extension, https.

您需要托管文件或使用类似下面的链接来允许此操作.

you need to host your file or use something like this link bellow to allow this.

允许Google Chrome浏览器使用XMLHttpRequest从本地文件加载URL

在Safari 11中,文件协议访问受到限制.

In Safari 11 file protocol access are limited.

[除非从Develop菜单中选择Disable Local File Restrictions,否则现在将阻止从file://进行的CORS和跨源访问.]

[CORS and cross origin access from file:// are now blocked unless Disable Local File Restrictions is selected from the Develop menu.]

这篇关于"XMLHttpRequest无法加载文件:///...预检响应不成功".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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