To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

$.getJSON 的用法

<!DOCTYPE HTML>
<html dir="ltr" lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
    <input id="btn" type="button" value="GET"/>
    <div id="container"></div>

    <script type="text/javascript">
        $(function(){
            $("#btn").bind("click",function(){
                $.getJSON("data.php",function(data){
                    console.log(data);
                })
            })
        })
    </script>
</body>
</html>
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());


$sel_query="select * from demotb";
mysql_query("set names utf8");
$sel_results=mysql_query($sel_query);

$array=[];
while ($arr=mysql_fetch_array($sel_results)) {
    foreach ($arr as $key => $value) {
        $arr[$key]=urlencode($value);
    }
    $array[]=$arr;
}
echo  urldecode(json_encode($array));

?>

 

posted on 2013-05-30 17:34  Ijavascript  阅读(325)  评论(0编辑  收藏  举报