Skip to content

Instantly share code, notes, and snippets.

@megurock
Last active August 29, 2015 14:04
Show Gist options
  • Save megurock/9b3bf4295ec0b7583fe7 to your computer and use it in GitHub Desktop.
Save megurock/9b3bf4295ec0b7583fe7 to your computer and use it in GitHub Desktop.
php example that returns jsonp
<?php
$callback = (isset($_GET['callback'])) ? $_GET['callback'] : 'callback';
$result = (isset($_GET['result'])) ? (int) $_GET['result'] : 0;
$error = (isset($_GET['error'])) ? (int) $_GET['error'] : 0;
$output = array(
"uid" => uniqid(),
"result" => $result,
"error" => $error
);
header("Content-Type: text/javascript; charset=utf-8");
echo $callback . "(" . json_encode($output, JSON_UNESCAPED_UNICODE) . ")";
exit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment