HTML源文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>demo5</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script> $(function(){ $('input').click(function() { var ul = $('#info>ul'); $.ajax({ url:'demo5.php?'+Math.random(), type:'get', dataType:'xml', success:function(xml){ $(xml).find('title').each(function(){ // $(this).text(); ul.append('<li>'+$(this).text()+'</li>') }); } }); }); }); </script> </head> <body> <input type="button" value="获取新闻列表" /> <div id="info"> <ul></ul> </div> </body> </html>
PHP源文件
<?php header('Content-type:text/xml;charset=utf-8'); $str = "<root> <title>否认放松计划生育政策</title> <title>劳教制度简史</title> <title>中共中央决定废止劳教制度</title> </root>"; echo $str; ?>