Created
May 30, 2012 09:21
-
-
Save serihiro/2834985 to your computer and use it in GitHub Desktop.
JSONP API SAMPLE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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