1

Hi if I have a jquery as follow for testing in local file, where should i store my sample.xml in local? On the URL i only want to call sample.xml without path.

 $(document).ready(function()
    {
      $.ajax({
        url: "sample.xml",
        dataType: "xml",
        success: function(data)
        {
            console.log(data);
            $("#output").text("Message from Success function"); 
        }, 
        error:function()
        {
            $("#output").text("Message from Error function");   
        }
      });
    }); 

3 Answers 3

1

If you don't want to use any path components, then you need to place the xml file in the same directory as the document including the JavaScript, as all urls are either absolute, or relative to either the root or the current directory.

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

Comments

1

If I understand you correctly you should just put the sample.xml file in your root directory. E.g the same folder as your index.html file or index.php file etc.

Comments

0

The first step is making sure you have jQuery included on your page. Second, you should check the XML file you are going to read and make sure it’s free of errors Finally, you just need to tell jQuery to read the file and print out the contents. Start by adding the document.ready function to the page.

ref this

http://www.think2loud.com/224-reading-xml-with-jquery/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.