JSONÊý¾Ý²Ù×÷
server2.php
- <?php
- //1
- $member['username'] = "aseoe";
- $member['password'] = "aseoe";
- $do = $_REQUEST['do'];
- //2
- $members['1']['username'] = "°®Ë¼×ÊÔ´Íø";
- $members['1']['password'] = "aseoev";
- $members['2']['username'] = "¼«ËÙÉè¼Æ";
- $members['2']['password'] = "jisu";
- $members['2']['address'] = "ÄϾ©ÊÐ";
- $members['third']['members']['address'] = "ÄϾ©ÊÐ";
- //3
- class addressClass{
- public $address = array();
- public function setAddress($array){
- $this->address = $array;
- }
- public function getAddress(){
- return $this->address;
- }
- }
- $addressObj = new addressClass();
- $addressObj->setAddress($members);
- switch($do){
- case "first":
- echo json_encode($member);
- break;
- case "second":
- echo json_encode($members);
- break;
- case "third":
- echo json_encode($addressObj);
- break;
- }
- ?>
ǰ̨ÏÔʾ
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>php-JSON2</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <script src="http://www.aseoe.com/statics/js/jquery-1.10.2.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- $("document").ready(function (){
- var url = "server2.php";
- var data = {"do":"first"};
- $.getJSON(url,data,function(res){
- $("#username").val(res.username);
- $("#password").val(res.password);
- });
- var data = {"do":"second"};
- $.getJSON(url,data,function(res){
- $("#members").val(res[1].username);
- $("#members").val(res.third.members.address);
- });
- var data = {"do":"third"}
- $.getJSON(url,data,function(res){
- $("#address").val(res.address[1].username);
- })
- });
- </script>
- </head>
- <body>
- <h2>һάÊý×é</h2>
- <input type="text" name="username" id="username" /> <br />
- <input type="password" name="password" id="password" /> <br />
- <h2>¶àάÊý×é</h2>
- <textarea id="members">
- </textarea>
- <h2>¶ÔÏó</h2>
- <textarea id="address">
- </textarea>
- <script type="text/javascript">
- </script>
- </body>
- </html>
±¾Õ¾»¶ÓÈκÎÐÎʽµÄתÔØ£¬µ«ÇëÎñ±Ø×¢Ã÷³ö´¦£¬×ðÖØËûÈËÀͶ¯³É¹û
תÔØÇë×¢Ã÷£º ÎÄÕÂתÔØ×Ô£º°®Ë¼×ÊÔ´Íø http://www.aseoe.com/show-12-468-1.html
תÔØÇë×¢Ã÷£º ÎÄÕÂתÔØ×Ô£º°®Ë¼×ÊÔ´Íø http://www.aseoe.com/show-12-468-1.html