Skip to content

Instantly share code, notes, and snippets.

@brettsnippets
Created May 19, 2013 17:33
Show Gist options
  • Save brettsnippets/5608365 to your computer and use it in GitHub Desktop.
Save brettsnippets/5608365 to your computer and use it in GitHub Desktop.
JavaScript: jQuery Ajax Call
$.ajaxSetup({cache:false});
$("a.linkContainingUrl").click(function(){
var post_url = $(this).attr('href');
var post = $('#post-here');
post.html('<img src="../img/ajax-loader.gif" />'); /* shows ajax loader until content is loaded */
post.load(post_url + ' #pull-this-content');
/* within the #post-here div, this will load in the post url from the a:link being clicked,
the #post- is pulling in the div that contains the content we want to bring in, instead of pulling
in the entire page. This could easily be anything like, #pull-this-content, it doesn't have to contain the post id */
return false; // this just tells the browser that the link shouldn't behave like a typical link
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment