主页面,5-18j.php
<!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <!--自此一下开始编写--> <script src="jquery-2.1.1.min.js"></script> </head> <body> <select id="m"> </select> </body> <script type="text/javascript"> $(document).ready(function(e) { $.ajax({ url:"J.php", dataType:"JSON", success: function(data) { var str=""; //JSON传输的数据是一个2维数组 for(var k in data) { str+="<option value='"+data[k][0]+"'>"+data[k][1]+"</option>"; } $("#m").html(str); } }) }); </script> </html>
J.php
<?php include("./Tp.class.php"); $db = new Tp(); $sql="select * from car"; $attr=$db->query($sql); echo json_encode($attr);
//2 维数组转化为 json 数据: json_encode() ?>