1 <script src="../../jquery-1.11.2.min.js"></script> 2 </head> 3 4 <body> 5 6 <select id="nation"> 7 8 </select> 9 10 <script type="text/javascript"> 11 12 $.ajax({ 13 url:"jsonchuli.php", 14 dataType:"JSON", 15 success: function(data){ 16 var str =""; 17 /*for(var i=0;i<data.length;i++) 18 { 19 str = str+"<option value='"+data[i].Code+"'>"+data[i].Name+"</option>"; 20 }*/ 21 22 for(var s in data) 23 { 24 str = str+"<option value='"+data[s].Code+"'>"+data[s].Name+"</option>"; 25 } 26 27 $("#nation").html(str); 28 } 29 }); 30 31 </script> 32 </body>
处理页面
<?php include("../DBDA.class.php"); $db = new DBDA(); $sql = "select * from nation"; //需要关联数组 //数组内容的编码格式:utf8的 echo json_encode($db->GuanQuery($sql));