简体   繁体   中英

Load XML File without AJAX

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

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 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 doesn't throw any error, but it never loads the file.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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