Skip to content

Instantly share code, notes, and snippets.

@serihiro
Created May 30, 2012 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serihiro/2834985 to your computer and use it in GitHub Desktop.
Save serihiro/2834985 to your computer and use it in GitHub Desktop.
JSONP API SAMPLE
<?php
/*
*
This JSONP API returns jsonp function call to JS script which called this JSONP API.
@response:
{*callback function name*}({[foo: "homhom"] , [bar: "anan"]});
*
*/
/*
Get callback function name.
*/
$callback = $_GET['callback'];
/*
Responce data
*/
$arr=array('foo'=>'homhom' , 'bar'=>'anan');
$encode = json_encode($arr);
/*
Set Header as json data
*/
header("Content-Type: application/json; charset=utf-8");
/*
This is body of response.
*/
echo $callback.'(' .$encode. ');';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment