Hi, I'm new to the programming, and I'm trying to learn jquery.
I have a problem with this code, I can not view the data in the xml file.
thank you very much.
<!DOCTYPE html>
<html>
<head>
<title>xxx</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>
<script type=text/javascript>
$(document).ready(function() {
//impostiamo la chiamata AJAX al Feed
$.ajax({
type: "GET",
url: "http://news.nationalgeographic.com/index.rss",
dataType: "xml",
success: parseXml,
error: errorMsg
});
//creaiamo la Funzione per leggere il file XML
function parseXml(xml) {
//svuotiamo il DIV output per il caricamento dei dati
$('#list').empty();
//scorriamo il file XML cercando le varie sezioni dello stesso
$(xml).find("item").each(function()
{
//dichiariamo delle variabili per ogni sezione
var title1 = $(this).find('title').text();
var link1 = $(this).find('link').text();
var desc1 = $(this).find('description').text();
var listItem = $('<li><a href="#">' + title1 + '<br />' + link1 + '<br />' + desc1 + '</a></li>');
//all'interno del DIV output inseriamo le sezioni concatenate
$("#list").append(listItem);
});
}
function errorMsg() {
//creaiamo un eventuale messaggio di errore al caricamento del file XML
$("#list").append("Errore nel caricamento del Feed");
}
});
</script>
</head>
<body>
<!- Prima Pagina->
<div data-role="page" id="home">
<!-Header->
<div data-role="header">
<h2>xxxxxxx</h2>
</div>
<!-Content->
<div data-role="content" >
<ul id="list"></ul>
</div>
<!-Footer->
<div data-role="footer">
<h2>Created By: xxxxxxxx</h2>
</div>
</div>
</body>
</head>
</html>