Created
October 17, 2012 00:10
-
-
Save susanBuck/3902926 to your computer and use it in GitHub Desktop.
ajax
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
// 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 | |
}, | |
}); | |
}); |
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
// 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