Created
February 5, 2009 11:10
-
-
Save nicalpi/58660 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
jQuery.ajaxSetup({ | |
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} | |
}) | |
//Send data via get if JS enabled | |
jQuery.fn.getWithAjax = function() { | |
this.click(function() { | |
$.get($(this).attr("href"), $(this).serialize(), null, "script"); | |
return false; | |
}) | |
return this; | |
}; | |
//------------------------------------- | |
//Send data via Post if JS enabled | |
jQuery.fn.postWithAjax = function() { | |
this.click(function() { | |
$.post($(this).attr("href"), $(this).serialize(), null, "script"); | |
return false; | |
}) | |
return this; | |
}; | |
//------------------------------------- | |
//Sumit the forms with ajax if JS enables | |
jQuery.fn.submitWithAjax = function() { | |
this.submit(function() { | |
$.post(this.action, $(this).serialize(), null, "script"); | |
return false; | |
}) | |
return this; | |
}; | |
//---------------------------------------- | |
$(document).ready(function() { | |
// All A tags with class 'get', 'post', 'put' or 'delete' and FORM tags with class 'ajax' will perform an ajax call | |
$('a.get').getWithAjax(); | |
$('a.post').postWithAjax(); | |
$('a.put').postWithAjax(); | |
$('a.delete').postWithAjax(); | |
$('form.ajax').submitWithAjax(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment