Created
November 16, 2015 18:19
-
-
Save tixastronauta/1964a8df912a40558fef to your computer and use it in GitHub Desktop.
PHP Handling JSONP requests
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 | |
$response = array( | |
array( | |
'title' => "My article 1", | |
'content' => 'Lorem lorem' | |
), | |
array( | |
'title' => "My article 2", | |
'content' => 'Lorem lorem' | |
) | |
); | |
header('Content-Type: application/json; charset=utf8'); | |
$json = json_encode($response); | |
if (array_key_exists('callback', $_GET)) | |
{ | |
echo $_GET['callback'] . '(' . $json . ')'; | |
} | |
else | |
{ | |
echo $json; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment