码迷,mamicode.com
首页 > Web开发 > 详细

第六十九天上课 text传值,json传值和xml传值

时间:2016-05-17 17:31:33      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

 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传值

标签:

原文地址:http://www.cnblogs.com/lovling/p/5502008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!