Skip to content

Instantly share code, notes, and snippets.

@dcneiner

dcneiner/json.js Secret

Created June 14, 2010 19:44
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 dcneiner/e546ce49f5ece0485f74 to your computer and use it in GitHub Desktop.
Save dcneiner/e546ce49f5ece0485f74 to your computer and use it in GitHub Desktop.
// Run immediately
jQuery.getJSON('http://path.com/to/json.php?callback=?', function(html){
// Make sure DOM is ready:
jQuery(function($){
$("#footer").before(html); // Example
});
});
<?php ob_start(); ?>
<h1>Extra HTML content here</h1>
<?php
$content = ob_get_contents();
ob_end_clean();
$content = json_encode( utf8_encode( $content ) );
echo isset($_GET['callback']) ? $_GET['callback'] . '(' . $content . ');' : $content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment