javascript - jQuery don't post form after preventdefault -


i have form loaded ajax, , inside form have render recaptcha control. when post form, first validate, , use webservice validate captcha. if data right want post form.

but last behavior don't append...

i read posts:

but none of solutions work... :(

my code:

$('#myform').submit(function (e) {  e.preventdefault();    var captchainfo = {    challengevalue: recaptcha.get_challenge(),    responsevalue: recaptcha.get_response(),   };    $.ajax({    type: 'post',    url: '@url.action("validatecaptcha")',    data: json.stringify(captchainfo),    contenttype: 'application/json; charset=utf-8',    datatype: 'json',    success: function (msg) {     if (msg) {      $('#myform').submit();     }     else {      helpers.setcaptcha("captcha");     }    },    error: function (req, status, error) {     alert("error: " + error);     helpers.setcaptcha("captcha");    },   });  }); 

how resolve this?

thanks in advance

when call .submit() same code called (ending in possibly infinite loop). try restructuring , passing value .submit() call, this:

$('#myform').submit(function (e, passthrough) {  // <-- declare here!!     if (passthrough) {  // <-- check here!!         e.preventdefault();          var captchainfo = {             challengevalue: recaptcha.get_challenge(),             responsevalue: recaptcha.get_response(),         };          $.ajax({             type: 'post',             url: '@url.action("validatecaptcha")',             data: json.stringify(captchainfo),             contenttype: 'application/json; charset=utf-8',             datatype: 'json',             success: function (msg) {                 if (msg) {                     $('#myform').trigger("submit", [true]);  // <-- pass here!!                 }                 else {                     helpers.setcaptcha("captcha");                 }             },             error: function (req, status, error) {                 alert("error: " + error);                 helpers.setcaptcha("captcha");             },         });     } }); 

the value passed (true), available in handler's parameters. check that. if it's true, know manually called , shouldn't validate captcha, passing through handler , allowing default behavior.

reference:


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -