Use jQuery To Retrieve Data From An XML File

GohzuBoggi

New Member
JQuery Function:\[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\]XML file:\[code\]<?xml version="1.0" encoding="UTF-8" ?><config> <host-prefix> <value>myprefix</value> </host-prefix> <host-url> <value>localhost</value> </host-url> <image-path> <value>imagePath</value> </image-path></config>\[/code\]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\].problem: 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.any help?
 
Back
Top