<script src="jquery-1.11.2.min.js"></script> </head> <body> <select id="sel"> </select> <script type="text/javascript"> $.ajax({ url:"xmlchuli.php", dataType:"XML", success: function(data){ //alert($(data).find("code").eq(1).text()); alert($(data).find("nation").attr("bs")); var allcode = $(data).find("code"); var allname = $(data).find("name"); var str =""; for(var i=0;i<allcode.length;i++) { var code = allcode.eq(i).text(); var name = allname.eq(i).text(); str = str +"<option value='"+code+"'>"+name+"</option>"; } $("#sel").html(str); } }); </script> </body>
处理页面
1 <?php 2 include("DBDA.class.php"); 3 $db = new DBDA(); 4 5 $sql = "select * from nation"; 6 7 $attr = $db->Query($sql); 8 9 echo "<nation bs='1'>"; 10 11 foreach($attr as $k=>$v) 12 { 13 echo "<n{$k}><code>{$v[0]}</code><name>{$v[1]}</name></n{$k}>"; 14 } 15 16 echo "</nation>";