Reputation: 13915
I need to make GET ajax request while form is being submitted. The page should not be reloaded. Tried to attach jQuery .submit()
handler but for some reason this does not work. Why?
...
$('#login-form').submit(function(){
e.preventDefault();
alert('Hi');
....
});
...
<form id="login-form" class="navbar-form" action="" method="get" >
<input id="email" class="span2" type="text" placeholder="Email">
<input id="password" class="span2" type="password" placeholder="Password">
<button type="submit" id="login-btn" class="btn btn-primary">Sign in</button>
</form >
Upvotes: 1
Views: 2761
Reputation: 318508
You forgot the e
argument in the callback.
$('#login-form').submit(function(){
should be
$('#login-form').submit(function(e){
^
After that it should work. If it doesn't make sure that you bind the handler either inside a document ready event or after the form has been defined.
Upvotes: 6