AJAX communication operations JSON data combat

Source: Internet
Author: User
Tags array json

JSON data manipulation



server2.php

  1. <?php
  2. 1
  3. $member [' username '] = "Aseoe";
  4. $member [' password '] = "Aseoe";
  5. $do = $_request[' do '];
  6. 2
  7. $members [' 1 '] [' username '] = "The network of resources";
  8. $members [' 1 '] [' password '] = "Aseoev";
  9. $members [' 2 '] [' username '] = "Speed design";
  10. $members [' 2 '] [' password '] = "jisu";
  11. $members [' 2 '] [' address '] = "Nanjing";
  12. $members [' third '] [' Members '] [' address '] = "Nanjing";
  13. 3
  14. Class addressclass{
  15. Public $address = Array ();
  16. Public Function setaddress ($array) {
  17. $this->address = $array;
  18. }
  19. Public Function getaddress () {
  20. return $this->address;
  21. }
  22. }
  23. $ADDRESSOBJ = new Addressclass ();
  24. $ADDRESSOBJ->setaddress ($members);
  25. Switch ($do) {
  26. Case "a":
  27. echo Json_encode ($member);
  28. Break
  29. Case "Second":
  30. echo Json_encode ($members);
  31. Break
  32. Case "Third":
  33. echo Json_encode ($ADDRESSOBJ);
  34. Break
  35. }
  36. ?>

Foreground display

  1. <! DOCTYPE html>
  2. <title>php-JSON2</title>
  3. <meta charset= "Utf-8" >
  4. <meta name= "viewport" content= "Width=device-width" >
  5. <script src= "Http://www.aseoe.com/statics/js/jquery-1.10.2.min.js" type= "Text/javascript" ></script>
  6. <script type= "Text/javascript" >
  7. $ ("document"). Ready (function () {
  8. var url = "server2.php";
  9. var data = {"Do": "I"};
  10. $.getjson (Url,data,function (res) {
  11. $ ("#username"). Val (Res.username);
  12. $ ("#password"). Val (Res.password);
  13. });
  14. var data = {"Do": "Second"};
  15. $.getjson (Url,data,function (res) {
  16. $ ("#members"). Val (Res[1].username);
  17. $ ("#members"). Val (res.third.members.address);
  18. });
  19. var data = {"Do": "Third"}
  20. $.getjson (Url,data,function (res) {
  21. $ ("#address"). Val (Res.address[1].username);
  22. })
  23. });
  24. </script>
  25. <body>
  26. <input type= "text" name= "username" id= "username"/> <br-/>
  27. <input type= "password" name= "password" id= "password"/> <br
  28. <textarea id= "Members" >
  29. </textarea>
  30. <textarea id= "Address" >
  31. </textarea>
  32. <script type= "Text/javascript" >
  33. </script>
  34. </body>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.