第一个页面:1.htm
<!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function(){ $.ajax({ type: "POST", url: "2.php?Json=true", data:"{TM:'ok'}", //无参也必须指定一个参数 success: function(data){ alert(data); var obj = eval("("+data+")"); //数组json对象 alert( obj); alert( obj.employees[0].firstName + " " + obj.employees[0].lastName); alert( obj.employees[1].firstName + " " + obj.employees[1].lastName); alert( obj.employees[2].firstName + " " + obj.employees[2].lastName); } }); }); </script> </body> </html>
第二个页面:2.php(直接返回如下字符串)
{"employees":[{"firstName":"张三","lastName":"Gates"},{"firstName":"lilililili","lastName":"Bush"},{"firstName":"Dench","lastName":"Carter"}]}