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

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -