最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ajax - Load xml file in a directory using javascript - Stack Overflow

programmeradmin2浏览0评论

I want to load a xml file using the javascript. I use the following code to load the xml file. The below coding loads the xml file when it is in the same folder.

if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.open("GET",'dineshkani.xml',false);
            xmlhttp.send();
            xmlDocument=xmlhttp.responseText;
            alert("loaded");

But i want to load the xml file in the particular location eg. c:/xml/dineshkani.xml

If i use the coding xmlhttp.open("GET",'c:/xml/dineshkani.xml',false); like this it wont load the xml file. Is there a way to load the xml file.

I want to load a xml file using the javascript. I use the following code to load the xml file. The below coding loads the xml file when it is in the same folder.

if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.open("GET",'dineshkani.xml',false);
            xmlhttp.send();
            xmlDocument=xmlhttp.responseText;
            alert("loaded");

But i want to load the xml file in the particular location eg. c:/xml/dineshkani.xml

If i use the coding xmlhttp.open("GET",'c:/xml/dineshkani.xml',false); like this it wont load the xml file. Is there a way to load the xml file.

Share Improve this question edited Jul 17, 2012 at 17:11 starbeamrainbowlabs 6,16610 gold badges47 silver badges77 bronze badges asked Jul 17, 2012 at 16:55 DineshkaniDineshkani 3,0037 gold badges32 silver badges45 bronze badges 1
  • You can't access the users file system under normal circumstances. – starbeamrainbowlabs Commented Jul 17, 2012 at 17:01
Add a ment  | 

3 Answers 3

Reset to default 2

Despite its name, XMLHttpRequest can be used for non-HTTP requests.
The following should work

xmlhttp.open("GET",'file:///C:/xml/dineshkani.xml',false);

The result status is 0 for success instead of 200. This is because the file and ftp schemes do not use HTTP result codes.

EDIT: However, some browsers, including Google Chrome disable this by default. It has to be enabled by starting Chrome with --allow-file-access. So if you are looking for a cross-browser solution, you should put the XML in your server directory.

HTML5 file api does not let you access the entire filesystem you get a sandboxed directory to work with. Link

Reference: MDN Page

Unfortunately, you can't access local files through AJAX.

You could try the HTML5 file access API, if you want.

I dont think it can be loaded use this link it is useful for xml file loading

Load xml

发布评论

评论列表(0)

  1. 暂无评论