Posted By

inreflection7 on 12/13/11


Tagged

php json proxy


Versions (?)

JSON with a PHP proxy


 / Published in: PHP
 

Use PHP to get JSON

1) set the PHP to the URL of the JSON 2) echo a variable with the loaded data 3) use a request via jQuery to get the variable from PHP

  1. /* PHP FILE - names 'example.php' */
  2.  
  3. <?php
  4. $content = file_get_contents('http://site.to.json/');
  5. echo $content;
  6. ?>
  7.  
  8. /* jQuery making the request */
  9.  
  10. $.getJSON('example.php', function(data){
  11. var items = [];
  12.  
  13. $.each(data, function(key, val){
  14. // do stuff with data
  15. log('key: ' + key + '. value: ' + val);
  16. });
  17. });

Report this snippet  

You need to login to post a comment.