lecture d'un fichier xml avec jquery
Bonjour,
Je veu lire les données d'un fichier XML à partir d'un fichier PHP.
Le fichier XML ressemble à cela :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<!DOCTYPE continents SYSTEM "test.dtd">
<sites>
<site id="0">
<url val="0">http://www.pckult.net</url>
<desc>
<title>PC Kult</title>
<brief>Résumé</brief>
<long>Description longue</long>
</desc>
</site>
<site id="2">
<title>Microsoft</title>
<url val="1">http://www.microsoft.ca</url>
<desc>
<brief>Résumé</brief>
<long>Description longue</long>
</desc>
</site>
<site id="3">
<title>Intel</title>
<url val="2" >http://www.intel.com</url>
<desc>
<brief>Résumé</brief>
<long>Description longue</long>
</desc>
</site>
</sites> |
et dans mon en-tête de fichier php , j'ai ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "GET",
url: "sites.xml",
dataType: "xml",
success: function(xml)
{
$(xml).find('site').each(
function()
{
var id = $(this).attr('id');
var title = $(this).find('title').text();
var url = $(this).find('url').text();
$('<div class="items" id="link_' + id + '</div>').html('<a href="' + url + '">' + title + '</a>').appendTo( '#Div_XML');
$(this).find('desc').each(
function()
{
var brief = $(this).find('brief').text();
var long = $(this).find('long').text();
$('<div class="brief"></div>').html(brief).appendTo('#link_'+id);
$('<div class="long"></div>').html(long).appendTo('#link_'+id);
});
});
},
error : function() {alert ('no file');},
});
});
</script> |
Mais le problème s'est qu'il ne m'affiche rien. Il fait l' ALERT('no file')
Que faire ?