aquaballoon

Ajax - getJSON

May 29th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.67 KB | None | 0 0
  1. <script>
  2. $(document).ready(function(){
  3.   $("button").click(function(){
  4.     $.getJSON("proxy.php",function(result){   //data.json
  5.       $.each(result, function(i, field){
  6.         $("div").append(field.name + " " + field.email + "<br>");
  7.       });
  8.     });
  9.   });
  10. });
  11. </script>
  12.  
  13. //proxy.php
  14. <?php
  15.     $url = 'http://202.179.30.16/data.json';
  16.     $htm = file_get_contents($url);
  17.     echo $htm;
  18. ?>
  19.  
  20. //http://202.179.30.16/data.json
  21. [
  22.   {
  23.     "id":1,
  24.     "name":"Jason Lee",
  25.     "email":"[email protected]"
  26.   },
  27.   {
  28.     "id":2,
  29.     "name":"Peter Lee",
  30.     "email":"[email protected]"
  31.   },
  32.   {
  33.     "id":3,
  34.     "name":"Angel Lee",
  35.     "email":"[email protected]"
  36.   }
  37. ]
Advertisement
Add Comment
Please, Sign In to add comment