Skip to content

Instantly share code, notes, and snippets.

@jordanbrock
Created January 7, 2010 03:33
Show Gist options
  • Save jordanbrock/270956 to your computer and use it in GitHub Desktop.
Save jordanbrock/270956 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
// All A tags with class 'get', 'post', 'put' or 'delete' will perform an ajax call
jQuery('a.get').live('click', function() {
var link = jQuery(this);
//$(document).trigger('loading.facebox');
$.get(link.attr('href'), function(data) {
if (link.attr('ajaxtarget'))
jQuery(link.attr('ajaxtarget')).html(data);
});
return false;
}).attr("rel", "nofollow");
jQuery('a.post').live('click', function() {
var link = jQuery(this);
$.post(jQuery(this).attr('href'), "_method=post", function(data) {
if (link.attr('ajaxtarget'))
jQuery(link.attr('ajaxtarget')).html(data);
});
return false;
}).attr("rel", "nofollow");
jQuery('a.put').live('click', function() {
var link = jQuery(this);
$.post(jQuery(this).attr('href'), "_method=put", function(data) {
if (link.attr('ajaxtarget'))
jQuery(link.attr('ajaxtarget')).html(data);
});
return false;
}).attr("rel", "nofollow");
jQuery('a.delete').live('click', function() {
var link = jQuery(this);
$.post(jQuery(this).attr('href'), "_method=delete", function(data) {
if (link.attr('ajaxtarget'))
jQuery(link.attr('ajaxtarget')).html(data);
});
return false;
}).attr("rel", "nofollow");
jQuery('a.get, a.post, a.put, a.delete').removeAttr('onclick');
jQuery('form.ajax').live('submit', function() {
jQuery(this).ajaxSubmit();
return false;
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment