Skip to content

Instantly share code, notes, and snippets.

@Stoffo
Last active September 21, 2015 14:28
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 Stoffo/a26e9c044473859dfd9a to your computer and use it in GitHub Desktop.
Save Stoffo/a26e9c044473859dfd9a to your computer and use it in GitHub Desktop.
simple example for an implemention of jsonp in php
<?php
$callback = $_GET['callback'];
$json = json_encode(['foo' => 'bar'], JSON_FORCE_OBJECT);
if ($callback) {
header('Content-Type: text/javascript');
echo $callback.'(';
echo $json;
echo ');';
// jqueryfunction({"foo":"bar"});
} else {
header('Content-Type: application/json');
echo $json;
//{"foo": "bar"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment