简体   繁体   中英

Javascript reading local/(same machine as the html) xml file

My goal is to read in a file test.xml which is in the same folder as my index.html.

I know that I can pull in script files with something like <script src="index.js></script> , but is there a way for me to do the same with an xml file <xml src="test.xml"><xml> .

I do not want to use the AJAX XMLHttpRequest because the index.html may not be hosted on an http server, but instead opened like a normal file in chrome.

Do I have any options when it comes to opening up this xml file, or will it have to be hosted on a http server? I guess another option would be to store the whole xml file inside of a javascript variable, but this seems unnecessary.

do not want to use the AJAX XMLHttpRequest because the index.html may not be hosted on an http server, but instead opened like a normal file in chrome.

Try launching chrome with --allow-file-access-from-files flag set . Should then be able to use XMLHttpRequest to retrieve file in local filesystem

*nix

/usr/bin/google-chrome --allow-file-access-from-files

*indows

start chrome --allow-file-access-from-files

See How do I make the Google Chrome flag “--allow-file-access-from-files” permanent? , Opening Chrome From Command Line

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