文件协议Ajax请求 [英] File Protocol Ajax Request

查看:120
本文介绍了文件协议Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个项目,其结构是这样的

I have made a project whose structure is like this

当我从firefox运行index.html时,它运行正常.

When I run my index.html from firefox, it is working fine.

但是我用Chrome打开它会出现CORS错误.

But I open it with my chrome it is giving CORS error.

现在,我的问题是Chrome不支持 file://协议ajax请求&因为我已经将项目分发给其他人,所以我不希望其他人仅在firefox上运行.

Now my problem is that chrome doesnot support file:// protocol ajax request & as I have distribute to my project to others I don't want other to run on firefox only.

内部,我在项目中使用ajax调用来加载资源.有人可以建议如何绕过该ajax调用来加载资源吗?是否有一些解决方案或任何第三方js可以帮助我.

Internally I am using ajax call in project, to load the resources. Can Somebody suggest how to bypass that ajax call to load resources?? Is there some solution or any third party js which can help me.

注意:请不要建议使用XAMPP,apache等在我可以放置我的项目并作为chrome本地主机运行的方式,因为我不希望用户强迫下载这些内容来运行我的项目.请提供其他有用的解决方案,以便我可以在代码和应用程​​序中进行一些更改.它适用于所有人.

Note: Please don't suggest to use XAMPP, apache etc where I can put my project and run as localhost for chrome as I don't want user to force to download these to run my project. Please give other useful solution where I can do some change in code & it works for everyone.

这里是您可以更好地了解我的问题的链接.

Here are the links from which you could understand my problem better.

Jquery中的Ajax无法从本地文件运行

AJAX代码不在本地运行

使用jQuery的AJAX请求不起作用

推荐答案

将数据直接嵌入到JavaScript或HTML中,然后从中读取数据.

Embed the data directly into the JavaScript or HTML and read it from there.

数据不会根据用户输入或数据库的内容进行更改,因此将其放在单独的"http"资源中不会带来巨大的好处.

The data isn't going to be changing based on user input or the contents of a database, so having it in a separate "http" resource doesn't bring huge benefits.

如果您想将数据存储为XML以使其更易于在开发环境中进行编辑,请编写一个构建工具以将其捆绑为嵌入式格式,然后再进行分发.

If you want to store the data in XML to make it easier to edit in your development environment, then write a build tool to bundle it up into an embedded format before distributing.

这篇关于文件协议Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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