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 39 40 41 42 43 44 45 46
|
parseXML = function(str){
alert('yoyop');
if(!$.support.htmlSerialize){
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(str);
return $(xmlDoc); // fix. jquery says, this is a dom, and treats it as one
}else{
return $(str); // jquery says, i have a string that is xml to convert to a dom, and treats it as one
}
}
function ajaxXML(){
$.ajax({
type : "POST",
url : "xml/sites.xml",
dataType: ($.browser.msie) ? "text" : "xml",
contentType: 'text/xml',
success : function(data) {
this.data = parseXML(data);
alert(this.data); // debug
$("body").prepend("<div id='toto' style='border: 2px solid red;'>"+this.data.text()+"</div>"); // debug
$(this.data).find('site').each(function(){
var id = $(this).attr('id');
var title = $(this).find('title').text();
var url = $(this).find('url').text();
var prenom = $(this).find('lenomatoto').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 longue = $(this).find('long').text();
var prenom = $(this).find('lenomatoto').text();
$('<div class="brief"></div>').html(brief).appendTo('#link_'+id);
$('<div class="long"></div>').html(longue).appendTo('#link_'+id);
$('<div class="prenom"></div>').html(prenom).appendTo('#link_'+id);
});
});
},
error: function(data) {
alert('erreur dans la requete Ajax');
}
});
} |
Partager