Reading local xml from javascript

I want to read locally stored xml and I want to read / write through javascript. my code is as follows

function saveBaseValue() { var xmlhttp; var XMLname="file:///C:/Users/setting.xml" if (window.XMLHttpRequest) { xmlhttp=new window.XMLHttpRequest(); xmlhttp.open("GET",XMLname,false); alert(xmlhttp.responseXML); } } 

In this case, xmlhttp.responseXML is null.

0
source share
1 answer

You can achieve your goal using the code below.

 <!DOCTYPE html> <html> <head> <script> function saveBaseValue() { var xmlhttp; var XMLname="file:///C:/Users/setting.xml" if (window.XMLHttpRequest) { xmlhttp=new window.XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { alert(xmlhttp.responseXML); } }; xmlhttp.open("GET",XMLname,false); xmlhttp.send(); } } saveBaseValue(); </script> </head> <body> <h1>Test</h1> </body> </html> 

But by default, your browser will not allow you to access this local file, as it concerns security, but if you still want to access it, then close all instances of chrome, get on the command line, change the directory to your chrome. exe is present and executed under the command.

 .\chrome.exe --allow-file-access-from-files --disable-web-security 
+2
source

All Articles