Skip to content

Instantly share code, notes, and snippets.

@karlbright
Created February 17, 2010 06:34
Show Gist options
  • Save karlbright/306369 to your computer and use it in GitHub Desktop.
Save karlbright/306369 to your computer and use it in GitHub Desktop.
$(function(){
// Set ajax logger event handlers
$("#ajaxlog").ajaxStart(function(){
$(this).text("Loading...");
}).ajaxSuccess(function(){
$(this).text("Success!");
}).ajaxError(function(){
$(this).text("Error!");
});
// Set default AJAX options
$.ajaxSetup({ cache: true, dataType: 'html', type: 'GET' });
// Function to create the link that will handle the AJAX request
$.fn.createAjaxLink = function() {
this.each(function(){
$(this).bind('click',onAjaxClick);
});
}
// Actions taken when ajax link is clicked
onAjaxClick = function() {
$.ajax({
success: onAjaxSuccess,
url: $(this).attr('href')
});
return false;
}
// Actions taken when ajax is loaded successfully
onAjaxSuccess = function(data) {
successHTML = $(data).find("div#page_content").html();
$("div#page_content").html(successHTML);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment