Form submitted multiple times when using the “submit” callback and $.ajax to post it

后端 未结 8 1504
闹比i
闹比i 2020-12-14 17:50

I\'ve been observing some strange behavior with the following code:

$.fn.submit_to_remote = function() {
  // I use .each instead of the .submit directly so          


        
相关标签:
8条回答
  • 2020-12-14 18:32

    Keep in mind that the jQuery submit() event looks for: <input type="submit">, <input type="image">, or <button type="submit"> in the form (http://api.jquery.com/submit/). Some frameworks default the type attribute to "submit", so if you are trying to override the default, change the type attribute to something else so it doesn't submit multiple times.

    0 讨论(0)
  • 2020-12-14 18:34

    Not sure about this strange behavior, but seems that unbinding the submit event will do the trick.

    So, before running the script returned by the $.ajax call, run this:

    $('.submit_to_remote').unbind("submit");
    

    That should remove previous bindings and leave just the new one.

    0 讨论(0)
提交回复
热议问题