I am trying to display some xml data from remote URL using jquery and ajax. In my xml, there are simply two elements to be accessed: title and url.
The structure of my xml file is as follows:
<list>
<lists>
<songs>
<title>Pumped Up Kicks - Foster the people</title>
<url>http://dc249.4shared.com/img/970884399/8b9afc1d/dlink__2Fdownload_2Fmf4- 10b_5F_3Ftsid_3D20111122-112912-f675aa20/preview.mp3</url>
</songs>
</lists>
</list>
And I have the following jquery code:
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://jeewanaryal.web44.net/SongsXML/nepaliSongs.xml",
dataType: "xml",
success: function (xml) {
var items = parseXml(xml);
doStuff(items);
}
});
});
function parseXml(xml) {
var items = [];
$(xml).find("songs").each(function () {
items.push({
name: $(this).find("title").text(),
value: $(this).find("url").text()
});
});
for (var i = 0; i < items.length; i++) {
$(".phoneGapAPI").append(items[i].name + " <button class=\"newsDiv\" onclick=\"openChildBrowser(" + items[i].value + ");\">click here</button> <br> <br />");
}
}
I can guess that I am doing wrong at the statement openChildBrowser("+items[i].value+");
How can I implement this? I need to pass the variable items[i].value inside the function openChildBrowser().
This code works fine displaying items[i].name but click here link does not let me to open that URL.
Jquery failed to to render your Xml (Error : XML Parsing Error: no element found Location: moz-nullprincipal:{9e622e17-2e96-4a4d-95e4-6f7b95d0b4d8} Line Number 1, Column 1:) .Try to add version information to that xml file.
like