Created
February 17, 2010 06:34
-
-
Save karlbright/306369 to your computer and use it in GitHub Desktop.
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
$(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