<!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)); ?>