title: Use jQuery To Retrieve Data From An XML File
body: <p><b>JQuery Function:</b></p>
  
  <pre><code>function readXMLData(tagName){
      var result;
      function loadfail(){
          alert("Error");
      }
  
      function parse(document){
          $(document).find(tagName).each(function(){
              result = $(this).find('value').text();
          });
      }
  
      $.ajax({
          type: "GET",
          url: 'config.xml',
          dataType: 'xml',
          success: parse,
          error: loadfail
      });
  
      //alert(result);
      return result;
  }
  </code></pre>
  
  <p><b>XML file:</b></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;config&gt;
      &lt;host-prefix&gt;
          &lt;value&gt;myprefix&lt;/value&gt;
      &lt;/host-prefix&gt;
  
      &lt;host-url&gt;
          &lt;value&gt;localhost&lt;/value&gt;
      &lt;/host-url&gt;
  
      &lt;image-path&gt;
          &lt;value&gt;imagePath&lt;/value&gt;
      &lt;/image-path&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>i have this xml file, and i need to retrieve data from it to use these data in another jquery function i call this function by <code>readXMLData("host-prefix")</code>.</p>
  
  <p><b>problem: </b>if i call function as i mentioned above, it returns <code>undefined</code>, whoever if i uncomment the <code>alert(result)</code> in <code>readXMLData</code> function, alert appears with <code>undefined</code> text but function return <code>myprefix</code> (the true result). and everything works fine. i need to remove alert(result) from my code i function still works proparly.</p>
  
  <p>any help?</p>