主页面:
<head> <script src="../jquery-2.2.3.min.js"></script> </head> <body> <select id="sel"></select> </body> <script type="text/javascript"> $(document).ready(function(e) { $.ajax({ url:"chulixml.php", dataType:"XML", success:function(data){ var ch = $(data).find("nation").children(); var str = ""; for(var i=0;i<ch.length;i++) { var code = $(ch[i]).find("code").text(); var name = $(ch[i]).find("name").text(); str+="<option value='"+code+"'>"+name+"</option>"; } $("#sel").html(str); } }); }); </script>
处理页面;
<?php include("../DBDA.php"); $db = new DBDA(); $sql = "select * from Nation"; $attr = $db->Query($sql); echo "<nation>"; foreach($attr as $k=>$v) { echo "<shuju{$k}>"; echo "<code>{$v[0]}</code>"; echo "<name>{$v[1]}</name>"; echo "</shuju{$k}>"; } echo "</nation>";