ajax - How can i call function in submithandler using jquery validation? -


i'm trying call ajax function once form validate not work me. below jquery on-submit method working fine me.

$('#promotionadd').on('submit',(function(e) {         e.preventdefault();         var formdata = new formdata(this);         promotionadd(formdata);         return false;     })); 

but need call same thing in submithandler not work.

$(document).ready(function () {         $('#promotionadd').validate({ // initialize plugin             rules: {                 mtitle: {                     required: true,                     minlength: 3,                  }             },             messages: {                 mtitle: "please enter promotion title",             },             submithandler: function (form) { // demo                 //alert(this);                 e.preventdefault();                 var formdata = new formdata(this);                 promotionadd(formdata);                 return false;             }         });     }); 

can 1 guide me i'm wrong , how can fix it. appreciate. thanks

in submithandler this refers validation plugin, not form plugin called on. use form parameter that's passed in function instead.

also note preventdefault() cause error e not defined , return false nothing. not required here in case validation plugin handles prevention of form submission you. try this:

submithandler: function (form) {     var formdata = new formdata(form); // use 'form' here     promotionadd(formdata); } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -