Make your links stay in a container, great for will_paginate / sorting headers and friends 🙂
Usage
// ajaxify all links that have “tab=my_container” in their href
$(“#my_container”).ajaxifyContainer(‘a[href*=”tab=my_container”]’)
Code
// make selected links in a container replace the container
// https://grosser.it/2012/06/21/jquery-pjaxcontainer-extensions
$.fn.ajaxifyContainer = function(selector){
selector = selector || 'a';
var $container = $(this);
$(selector, $container).live('click', function(){
$container.html("Loading ...").load($(this).attr("href"));
return false;
});
};
';
var $container = $(this);
$container.html(loading).load(url, function(response, status, xhr){
if (status == "error") {
$container.html("Error:" + xhr.status + " " + xhr.statusText);
} else {
if(callback) callback(response, status, xhr);
}
});
};