Last active
August 29, 2015 14:17
-
-
Save jamesmontalvo3/47b44bfe2b8d46cc22a1 to your computer and use it in GitHub Desktop.
PHP implementation for returning JSON and HTML via JSONP
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 | |
// set content type to javascript (else it'll think it's HTML) | |
header( 'Content-Type: application/javascript; charset=utf-8' ); | |
// allow the requester to specify a callback function | |
$callback = isset( $_GET['callback'] ) ? $_GET['callback'] : 'callback'; | |
// retrieve the contents of the current event's HTML file | |
$configHtmlText = file_get_contents( __DIR__ . '/Event1069.html' ); | |
// stick the html string into a php array (with key "html") then | |
// create JSON out of it | |
$stringifiedJson = json_encode( array( | |
'html' => $configHtmlText | |
) ); | |
// return javascript callback function | |
echo "$callback( $stringifiedJson );"; |
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 | |
// set content type to javascript (else it'll think it's HTML) | |
header( 'Content-Type: application/javascript; charset=utf-8' ); | |
// allow the requester to specify a callback function | |
$callback = isset( $_GET['callback'] ) ? $_GET['callback'] : 'callback'; | |
// retrieve the contents of the current event's HTML file | |
$configJsonText = file_get_contents( __DIR__ . '/Event1069.json' ); | |
// return javascript callback function | |
echo "$callback( $configJsonText );"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment