asp.net mvc - MVC3, jQuery, Form submit: multiple submissions -


i have following jquery code intercept form submission , turn ajax call:

$("form.section_change").off("submit").on("submit", function () {     var section = $(this).attr("data-section");     var initializer = $(this).attr("data-initfunc");     $.ajax({         url: this.action,         type: this.method,         data: $(this).serialize(),         error: function (a, b) {             debugger;         },         success: function (result) {             $("div#" + section).html(result);             bindextenders();             if (initializer != null) {                 var func = window[initializer];                 func();             }         }     });     return false; }); 

conceptually, happens ajax call returns html used replace div that's within form tag. bindextenders() function call "rebinds" jquery bindings, including 1 described snippet. initializer function optional item runs specified javascript function.

when submit form first time i'm on page callback called once, expected. however, on subsequent submissions callback called multiple times (usually twice, more that).

i'd figure out how callback gets called once.

you can this:

$('body').on('submit', 'form.section_change', function() { // ... }); 

this way don't need rebind. see here: jquery


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -