0

I had a file data.php

<div class="content">hello</div>

I can fetch data in main file using

main.php

<div id="content1"></div>
<script>
$.post("data.php",function(r,s){$("#content1").html(r);});
</script>

This script fetches the data from data.php even if i try data.txt it also works but when i convert data.php into data.xml this does not work

<div id="content1"></div>
<script>
$.post("data.xml",function(r,s){$("#content1").html(r);});
</script>

what should i do to fetch data from xml file. please help

5
  • Refer this link w3schools.com/ajax/ajax_xmlfile.asp You wil find a very beautiful explanation . Commented Sep 1, 2016 at 9:36
  • Have you tried $.load rather than post? Commented Sep 1, 2016 at 9:46
  • Check your server settings for the filetype. jquery will see that it's an xml file and handle it differently. Commented Sep 1, 2016 at 9:47
  • @RahulSingh in link javascript ajax is used i want to use jquery Commented Sep 1, 2016 at 10:07
  • @freedomn-m $.lost also not working, i am doing it at localhost Commented Sep 1, 2016 at 10:12

1 Answer 1

1

If you want to use jquery ajax then try this method.

  $.ajax({
                type: "POST",
                url: "data.xml",
                dataType: "xml",
                success: function (xml) {
                    var xmlDoc = $.parseXML(xml),
                    $xml = $(xmlDoc);
                    $title = $xml.find( "title" );
                    $("#someElement" ).append( $title.text() );
                }
            });

You need to parseXml data.

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

1 Comment

If needed you can refer this link also. stackoverflow.com/questions/16417211/…

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.