Reputation: 3906
On a button click, I'm submitting a jQuery form by:
jQuery('#form').submit();
which I can see in the network sending a call and receiving a result. The thing is that I would like to catch the result, how do I do so ? I've tried to do:
jQuery('#form').submit(function(){ alert('test');});
but this didn't work.
Upvotes: 1
Views: 120
Reputation: 35572
You should be using AJAX With Post.
Serialize the form data and submit and wait for response, as
$.post("action.php", $("#form").serialize(),function(data) {
alert("Response data: " + data);
});
Upvotes: 1
Reputation: 10638
What do you mean 'catch result' of submit? Result of submit is usually new page and it can't be caught by javascript. If you need to perform some processing of result page you should write that javascript in result page.
Upvotes: 0
Reputation: 636
You want to catch the result? Means you don't want to send it to the Server?
try
jQuery('#form').submit(function(e){
e.preventDefault();
alert('test');
});
Upvotes: 1