0

I have an xml file created in E drive E:\xmlData.xml.
I need to load this xml file into jsp/html file on page load using JavaScript/jQuery.

2
  • As far as I know, JavaScript can only read local files through a file-upload form. Commented Aug 8, 2012 at 5:33
  • @JCOC611: Can't we use some jquery ajax to get the file from remote location ie driver Commented Aug 8, 2012 at 5:38

3 Answers 3

1

Generally speaking JavaScript is client-side technology. It doesn't have access to your local file system and you can't load a file from there. But HTML5 provides the File System API. It allows you to solve your issue. Here's an example.

Sign up to request clarification or add additional context in comments.

Comments

0

Create a Rest API based server. which will return the xml when the request is given by an Ajax call.

Comments

0

jQuery provides a method $.get which can capture the data from a URL. So to "read" the xml document, it needs to be accessible through a URL. for using jQuery you must download jQuery javascript library from http://jquery.com/ and put it on the current project/solution file.

use this inside the head tag :

<script src="jquery-1.7.2.min.js" type="text/javascript"></script>

This is an example script this will alert xml file content on load...

<script type="text/javascript">
    var localFileUrl = '/Yourdirectory/file.xml';

    $(document).ready(function() {
        $.get(localFileUrl , function(fileContent) {
            alert(fileContent);
        });
    });
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.