不使用本地/网络服务器读取 xml [英] Reading xml with out using local/webserver

查看:28
本文介绍了不使用本地/网络服务器读取 xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 javascript 新手.我试图从应用程序文件夹中读取一个 xml 文件,该文件夹位于硬盘中.仅 HTTP 支持跨源请求."这是正在抛出的错误.

I am new to javascript.I am trying to read an xml file from application folder, which is located in the hard disk. "Cross origin requests are only supported for HTTP." this is the error that is being thrown.

如果我尝试通过本地服务器/网络服务器访问同一个 xml 文件,它工作正常.因为我正在尝试开发离线应用程序.我如何让它在本地工作.

If I try to access the same xml file via local server/web server it works fine. Since i am trying to develop offline application. How do i make it work locally.

谢谢,

推荐答案

我可以想象你想要开发离线应用程序的几个原因:

I can imagine a few reasons why you want to develop an offline application :

如果你想要一个实际的在线应用程序,它也可以离线工作(考虑同步的东西,或者不考虑)看看 HTML5:http://diveintohtml5.info/offline.html

If you want an actual online application that might also work offline (with sync stuff in mind, or not) look at HTML5 : http://diveintohtml5.info/offline.html

现在,如果您认为我没有服务器端逻辑,所以我不需要服务器,但我仍然在挖掘具有一些 html UI 的 javascript 应用程序",并且很明显我们几乎都在某一时刻想到了什么令人惊叹的 UI 功能在最近的 Web 导航器中带来了智能 API,所有这些 API 都在本地运行并且绝对可移植.嗯,所以我只需要一堆 javascript 文件,一些 html 和 css,我给它任何 xml/json/csv 数据,它位于我的企业网络的某个地方,在这里我不必在其中写下一些蹩脚的 VBA一个巨大的 Excel 表格,或者通过 Web 服务器和防火墙影响我的 IT/IS,我可以部署强大的数据查看器和指标等等."

Now, if you think "I have no server-side logic so I do not need a server, but I still dig having a javascript application with some html UI", and clearly we nearly-all thought at one point seeing what amazing UI capabalities bring smart APIs in a recent web navigator, all running locally and absolutely portable. "Well so I just need a bunch of javascript files, some html and css, I give it whatever xml/json/csv data to it that is somewhere on my enterprise network and here I go without having to either write down some crappy VBA within a huge excel sheet, or impact my IT/IS with web servers, and firewalls and such I can deploy powerful data viewers and indicators and such."

我的意思是我确实对我说过这些话.而且我确实多次鄙视导航员的行为,直到我想要获取数据然后抱怨只是为了获取那些该死的数据!

I mean I did say these things to me. And I did many times despise navigators behave just fine until I want to get the data and then complain just to fetch those damn data !

但我必须承认,网络导航器首先必须是可信任的,并且必须承诺只浏览一致的网络应用程序(通过安全数据的安全行为实现的安全逻辑),这意味着在某处设置沙箱有界限.让应用程序只是我电脑上的任何东西",同时连接到在导航器中运行的 www 太开放了,不可靠.

But I do have to admit that web navigators must first be trustful, and to be so, have to commit on only browsing consistent web-apps (safe logic implemented by safe behaviors on safe data), which means setting somewhere a sandbox with boundaries. Letting the app just be "whatever is on my computer" and at the same time being connected to www running within a navigator is just too open to be reliable.

如果您想拥有导航器的 html/css/javascript 功能,只需使用网络导航器引擎(例如 webkit).重要的是,最终它将成为您自己的应用程序,并且您将能够做任何你想做的事,代价是不得不向你的 IS/IT 团队解释这是无害的,因为你必须这样做.

If you want to have the html/css/javascript power of a navigator just use a web navigator engine (such as webkit.) What matter is that at the end it will be your own application, and you will be able to do whatever you want to do, at the expense of having to explain your IS/IT team that is harmless, because you have to.

或者,如果您努力认识到数据提供者已经是服务器的责任,请转到客户端服务器,手头有很多替代方案:

Or if you make the effort to recognize that data provider is already a server responsibility go client server, with plenty of alternatives at hand :

  • 您可以使用通常的 Apache(一些调试多合一的软件包,例如 wamp 在几分钟内就可以正常工作)
  • 您可以使用全栈网络服务器 API(例如 Play!)来运行后台并在其上使用您喜欢的导航器(允许您在某个时候访问网络),
  • 或者使用nodejs和webkit这样的组合或者其他的多合一(比如https://github.com/rogerwang/node-webkit )

与您的实际需求相比,我可能走得太远了:让该死的代码工作.为此,有很多关于本地文件跨源请求仅支持 HTTP"的堆栈溢出问题的回答.

I went probably too far compared to your actual need : make that damn code work. And for that there are many answered questions on stack overflow about local file "Cross origin requests are only supported for HTTP" stuff.

但这次我必须表明我的观点.希望它不会完全偏离轨道;)

But I had to make my point, this time. Hope it is not completely off track ;)

这篇关于不使用本地/网络服务器读取 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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