Ever needed a quick way to submit a form through ajax?
Jquery plus a nice little plug-in can help.
Download jquery and the plugin
-
$(document).ready(function() {
-
var options = {
-
target: ‘#outPutDiv’, // target element(s) to be updated with server response
-
beforeSubmit: showRequest, // pre-submit callback
-
success: showResponse // post-submit callback
-
};
Event
-
$(‘#formId’).submit(function() {
-
-
$(this).ajaxSubmit(options);
-
-
return false;
-
});
And then simply replace the formId and outPutDiv and your form will be submitted via ajax.
So easy. No unnecessary page reloading needed.
http://www.malsup.com/jquery/form/#code-samples
Some other available options
-
url: url // override for form’s ‘action’ attribute
-
type: type // ‘get’ or ‘post’, override for form’s ‘method’ attribute
-
dataType: null // ‘xml’, ’script’, or ‘json’ (expected server response type)
-
clearForm: true // clear all form fields after successful submit
-
resetForm: true // reset the form after successful submit
-
// jquery $.ajax options can be used here too, for example:
-
timeout: 3000
…






Subscribe to this blog