不使用AJAX加载XML文件 [英] Load XML File without AJAX

查看:73
本文介绍了不使用AJAX加载XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将静态XML文件加载到HTML中并在没有AJAX请求的情况下处理它。

I want to load a static XML file into HTML and process it without a AJAX request.

我不想发出AJAX请求,因为,当那个html文件在没有网络服务器的情况下查看(这是我们的要求),

I dont want to make an AJAX request because, when that html file is viewed without a webserver (which is a requirement for us),


Chrome会抛出以下错误并停止播放给我们。
XMLHttpRequest无法加载file:// C:/project/abcd.xml。收到无效回复。因此不允许原点'null'访问。

Chrome throws following error and it stops playback for us. XMLHttpRequest cannot load file://C:/project/abcd.xml. Received an invalid response. Origin 'null' is therefore not allowed access.

IE11不会抛出任何错误,但它永远不会加载文件。

IE11 doesn't throw any error, but it never loads the file.

有没有办法将此静态XML文件添加为脚本或链接等标记的一部分?
加载后我想用JQuery解析XML。

Is there any way to add this static XML file as part of a tag like script or link? Once loaded I want to parse the XML using JQuery.

推荐答案

简短回答 - 不,你不能。

Short answer - no you can't.

您无法使用JS / AJAX或服务器端语言(没有Web服务器时没有)将XML加载到网页中。这当然适用于使用jQuery在HTML页面中对数据进行后处理的意图。

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). This applies of course to the intention of post-processing the data in the HTML-page using jQuery.

由于浏览器遵循了这一点,因此停止了AJAX请求同源政策(见 http://en.wikipedia.org/wiki/Same-origin_policy )。如果不运行本地Web服务器或将文件放到公共Web服务器上,就无法解决这个问题。

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). You can't work around that without either running a local web server or putting the files onto a public web server.

这篇关于不使用AJAX加载XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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