Advertisement
Guest User

PHP serve json

a guest
Feb 14th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.39 KB | None | 0 0
  1. <?php
  2. //Send proper content-type
  3. header('Content-Type: application/json');
  4. if(isset($_POST['id'])) {
  5.     //Get data from database here
  6.     //and serve it with
  7.     //json_encode()
  8.     echo json_encode(
  9.         array(
  10.             array('id' => 1, 'name' => 'Human'),
  11.             array('id' => 2, 'name' => 'Orc'),
  12.             array('id' => 3, 'name' => 'Dwarf'),
  13.         )
  14.     );
  15. }
  16. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement