After you click the button submit, usually the form is sent to the server, and all client script actions are terminated. Therefore, if you do not AJAXify your form, this will not work. In order to AJAXify your form, you can attach to the submit event and replace the default action:
$(function() {
$('#theForm').submit(function() {
$('#someHiddenDiv').show();
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function() {
$('#someHiddenDiv').hide();
}
});
return false;
});
});
and your markup:
<form id="theForm" action="/foo" method="post">
<input name="foo" type="text" />
<input type="submit" value="Go" />
</form>
<div id="someHiddenDiv" style="display: none;">Working...</div>
source
share