Skip to content

Instantly share code, notes, and snippets.

@susanBuck
Created October 17, 2012 00:10
Show Gist options
  • Save susanBuck/3902926 to your computer and use it in GitHub Desktop.
Save susanBuck/3902926 to your computer and use it in GitHub Desktop.
ajax
// Fire ajax when some button is clicked
$('#button').click(function() {
$.ajax({
type: 'POST',
url: '/controller/method/',
beforeSend: function() {
},
success: function(response) {
// Response is anything that is echo'd out from the controller.
// So say the controller echo's out "Your data has been saved!" and you want to display that in a results div on your page...
$('#results').html(response);
},
data: {
foo: bar
},
});
});
// Make a form submit via Ajax
// Requires this plugin: http://www.malsup.com/jquery/form/
var options = {
type: 'post',
url: '/controller/method/',
beforeSubmit: function() {
},
success: function(response) {
// Response is anything that is echo'd out from the controller.
}
};
$('#form').ajaxForm(options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment