Skip to content

Instantly share code, notes, and snippets.

@tixastronauta
Created November 16, 2015 18:19
Show Gist options
  • Save tixastronauta/1964a8df912a40558fef to your computer and use it in GitHub Desktop.
Save tixastronauta/1964a8df912a40558fef to your computer and use it in GitHub Desktop.
PHP Handling JSONP requests
<?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