Skip to content

Instantly share code, notes, and snippets.

@naosim
Created January 2, 2017 01:51
Show Gist options
  • Save naosim/b67d1e063b6b2ddfcfa470041709ccef to your computer and use it in GitHub Desktop.
Save naosim/b67d1e063b6b2ddfcfa470041709ccef to your computer and use it in GitHub Desktop.
JSONP in PHP
function sendJsonResponse($map) {
$json = json_encode($map);
// JSON
if(!isset($_GET['callback'])){
header("Content-type: application/json");
echo $json;
return;
}
// JSONP
header("Content-type: application/javascript");
$callback=$_GET['callback'];
print <<<END
$callback($json);
END;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment