简体   繁体   English

不使用AJAX加载XML文件

[英]Load XML File without AJAX

I want to load a static XML file into HTML and process it without a AJAX request. 我想将静态XML文件加载到HTML中并在没有AJAX请求的情况下进行处理。

I dont want to make an AJAX request because, when that html file is viewed without a webserver (which is a requirement for us), 我不想提出AJAX请求,因为在没有网络服务器的情况下查看该html文件时(这是我们的要求),

Chrome throws following error and it stops playback for us. Chrome抛出以下错误,并为我们停止播放。 XMLHttpRequest cannot load file://C:/project/abcd.xml. XMLHttpRequest无法加载file:// C:/project/abcd.xml。 Received an invalid response. 收到无效的回应。 Origin 'null' is therefore not allowed access. 因此,不允许访问原始“空”。

IE11 doesn't throw any error, but it never loads the file. IE11不会引发任何错误,但是它永远不会加载文件。

Is there any way to add this static XML file as part of a tag like script or link? 有什么方法可以将此静态XML文件添加为脚本或链接之类的标签的一部分? Once loaded I want to parse the XML using JQuery. 加载后,我想使用JQuery解析XML。

Short answer - no you can't. 简短答案-不,您不能。

You cant load the XML into a web page without either using JS/AJAX or a server side language (which you don't have without a web server). 您不能在不使用JS / AJAX或服务器端语言(没有网络服务器的情况下)的情况下将XML加载到网页中。 This applies of course to the intention of post-processing the data in the HTML-page using jQuery. 这当然适用于使用jQuery对HTML页面中的数据进行后处理的意图。

The AJAX request is stopped due to the fact that browsers adhere to the "same origin policy" (See http://en.wikipedia.org/wiki/Same-origin_policy ). 由于浏览器遵守“相同来源策略”,因此AJAX请求被停止(请参阅http://en.wikipedia.org/wiki/Same-origin_policy )。 You can't work around that without either running a local web server or putting the files onto a public web server. 如果没有运行本地Web服务器或将文件放入公共Web服务器,就无法解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM