asp.net mvc - ASP MVC prevent submit form with jquery function on separate js file -


I am trying to submit a form via AJAX using the following code:

  $ (document) .on ('submit', '# form-discount', function (e) {e.preventDefault () $ .ajax ({cache: false, async: true, type: 'POST' , Url: $ (this) .attr ('verb'), data: $ (this). Serialize (), preceded: function () {}, success: function (data) {},})}});  

But it is reaching the controller before reaching this JavaScript code, so this takes twice the controller action. How can I avoid this behavior?

You need to return a false return with your call to stop the page from completing postback. I

Some:

  $ (document) .on ('submit', '# form-discount', function (e) {e.preventDefault () $ (action), data: $ (this ). Serialize (), preceded: function () {}, success: function (data) {},}); Returned; // stop postback});  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -