标签:
<select id="sel"> </select> </body> <script type="text/javascript"> $(document).ready(function(e) { $.ajax({ url:"ChuLi.php", dataType:"JSON", success: function(data){ //alert(data); var str = ""; for(var k in data) { str+="<option value=‘"+data[k][0]+"‘>"+data[k][1]+"</option>"; } $("#sel").html(str); } }); }); </script> </html>
处理页面
<?php include("../DBDA.php"); $db = new DBDA(); $sql = "select * from Nation"; $attr = $db->Query($sql); echo json_encode($attr);//将数组直接转换成json ?> <script src="../jquery-1.11.2.min.js"></script> </head> <body>
XML:页面之间传递数据,跨平台传递
HTML:超文本标记语言,核心标签
XML特点:
1.标签名可以自己定义
2.有且只有一个根
3.大小写敏感
4.标签必须完整
<script src="../jquery-1.11.2.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> </html>
xml处理页面
<?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>";
标签:
原文地址:http://www.cnblogs.com/yy01/p/5519685.html