0

my work consist to read this distant xml file :http://www.velib.paris/service/stationdetails/paris/901 ,in html file by using Ajax ! this is my code:

<script type="text/javascript">

getReadXmlFile();

function getReadXmlFile(){
    alert("recherche d fichier");
    $.ajax({
            type: "GET",
            url: "http://www.velib.paris/service/stationdetails/paris/901",
            dataType: "xml",
            success: parseXml
        });
    alert("obtention du fichier");
}

function parseXml(xml){
    alert('debut du parse');
    var up=$(xml).find("updated").text();
    alert(up);
}          
</script>

But it does not run i don know why thank for help ! i need your help please !

Dandy
  • 1,466
  • 16
  • 31
Boris k.
  • 7
  • 1
  • 7
  • What do you mean "it does not run"? Any errors? It looks like this is because you're doing an asynchronous call and your `parseXml` function is being run before anything is returned by your AJAX. Check out this answer for an example on how to create a function after performing an asynchronus call:http://stackoverflow.com/questions/9337168/jquery-creating-a-generic-ajax-function – Dandy Aug 26 '16 at 01:27

1 Answers1

0

I have tried your code at JSFiddle (with unrelated modification) and it works properly.

getReadXmlFile();

function getReadXmlFile(){
  alert("recherche d fichier");
  $.ajax({
    type: "POST", // JSFiddle needs this, it's not related to your issue
    url: "/echo/xml/",
    dataType: "xml",
    data: {
      xml: `
        <?xml version="1.0" encoding="utf-8"?>
        <station>
          <available>1</available>
          <free>19</free>
          <total>20</total>
          <ticket>1</ticket>
          <open>1</open>
          <updated>1472183109</updated>
          <connected>1</connected>
         </station>
      `
    },
    success: parseXml
  });
  alert("obtention du fichier");
}

function parseXml(xml){
  alert('debut du parse');
  var up=$(xml).find("updated").text();
  alert(up);
}    

Check this JSFiddle

Without error message given, the only thing I can think of is do you have jQuery loaded correctly?

PSWai
  • 1,198
  • 13
  • 32