Reading XML with jQuery

阅读更多

1、sites.xml



   
     Think2Loud
	http://www.think2loud.com
     
       this is the brief description.
       ...and this is the long description.  See how long it is :)
     
   
   
     jaredharbour.com
	http://www.jaredharbour.com
     
       this is the brief description.
       ...and this is the long description.  See how long it is :)
     
   
   
     Css Tricks
	http://www.css-tricks.com
     
       this is the brief description.
       ...and this is the long description.  See how long it is :)
     
   
 

 

2、code

$(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();
				$('').html(''+title+'').appendTo('#page-wrap');
				$(this).find('desc').each(function(){
					var brief = $(this).find('brief').text();
					var long = $(this).find('long').text();
					$('
').html(brief).appendTo('#link_'+id); $('
').html(long).appendTo('#link_'+id); }); }); } }); });
 

 

你可能感兴趣的:(XML,jQuery,CSS,Ajax,HTML)