Monday, 16 February 2015

reading file contents by specifying file location within script tag using javascript



hi my requirement is i have to read an xml file from the local folder(no web server here) then parse this xml and populate the html form fields. i tried the below approach



<script type='text/xml' id='XMLData'>
<category><cd><artist>mk</artist><id>12</id></cd></category>
</script>
<script>
xml = $($.parseXML($('#XMLData').text())),
plans = xml.find('cd');


plans.each(function () {
var artist= $(this).find('artist').text();
$('#artist').val(artist);
});
</script>
<html>
<input type="text" id="artist">ARTISt:</input>
</html>


this works fine. but what i cannot specify the xml file content as shown above i need to read the xml file content dynamically.


i thought of specifying the location of file in the script tag as below



<script type='text/xml' id='XMLData' src="./xmlfile/cds.xml></script>


this is where i am stuck, i want to read the xml file contents from the src file, if anyone can give me a hint as how to contiue would be great. thanks in advance


No comments:

Post a Comment