第六十九天上课 text传值,json传值和xml传值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第六十九天上课 text传值,json传值和xml传值相关的知识,希望对你有一定的参考价值。
text传值 : 主页面代码(读取数据库数据)
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>AJAX</title> <script src="js/$Jquery.js"></script> </head> <body> <input type="button" value="显示" id="btn" /> <table id="xianshi" width="1000px" border="1px" cellpadding="0" align="center"> </table> </body> <script> $(document).ready(function() { $(‘#btn‘).click(function() { $.ajax ({ url:"uindex.php", dataType:"TEXT", success: function(a) { var hang=a.split(‘|‘); var str="<tr align=‘center‘><td>代号</td><td>姓名</td><td>性别</td><td>民族</td><td>生日</td><td>*</td></tr>"; for(var i=0;i<hang.length;i++) { var j=hang[i].split(‘-‘); str+="<tr align=‘center‘><td>"+j[0]+"</td><td>"+j[1]+"</td><td>"+j[2]+"</td><td>"+j[3]+"</td><td>"+j[4]+"</td><td>删除</td></tr>"; } $(‘#xianshi‘).html(str); } }); }); }); </script>
text传值(后台页面)index1.php
<?php include "class/unionmysql-class.php"; $db=new unionMysql(); $sql="select * from info"; $result=$db->queryStr($sql); echo $result;
json传值 : 主页面代码(下拉列表)
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>AJAX</title> <script src="js/$Jquery.js"></script> </head> <body> <select id="nation"></select> </body> <script> $(document).ready(function() { $.ajax ({ url:"test.php", dataType:"JSON", success:function(e) { var str=‘‘; for(var i=0;i<e.length;i++) { str+="<option valur="+e[i][0]+">"+e[i][1]+"</option>"; } $(‘#nation‘).html(str); } }); }); </script>
json传值(后台界面)test.php
include "class/unionmysql-class.php"; $db = new unionMysql(); $sql = "select * from nation"; $result=$db->query($sql); echo json_encode($result); //将数组转换成json
xml传值 : 主页面代码(下拉列表)
<title>AJAX</title> <script src="js/$Jquery.js"></script> </head> <body> <select id="nation"></select> </body> <script> $(document).ready(function() { $.ajax ({ url:"test.php", dataType:"XML", success:function(e) { var nation=$(e).find(‘nation‘).children(); var str=‘‘; for(var i=0;i<nation.length;i++) { var code=$(nation[i]).find(‘code‘).text(); var name=$(nation[i]).find(‘name‘).text(); str+="<option value=‘"+code+"‘>"+name+"</option>"; } $(‘#nation‘).html(str); } }); }); </script>
xml传值(后台界面)test.php
<?php include "class/unionmysql-class.php"; $db=new unionMysql(); $sql="select * from nation"; $result=$db->query($sql); echo "<nation>"; foreach($result as $k=>$i) { echo "<shuju{$k}>"; echo "<code>{$i[0]}</code>"; echo "<name>{$i[1]}</name>"; echo "</shuju{$k}>"; } echo "</nation>";
以上是关于第六十九天上课 text传值,json传值和xml传值的主要内容,如果未能解决你的问题,请参考以下文章