JSON with a PHP proxy


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.