jQuery don't post form after preventdefault
Hi.
I've a form loaded with AJAX and this form has a reCaptcha.
When post the form I want to validate the captcha and if there is ok post the form to server.
But I can't...
My code (based with other help)
- $('#myForm').submit(function (e, passThrough) {
- if (passThrough === undefined) {
- e.preventDefault();
- var captchaInfo = {
- challengeValue: Recaptcha.get_challenge(),
- responseValue: Recaptcha.get_response(),
- };
- $.ajax({
- type: 'POST',
- url: captchaValidateUrl,
- data: JSON.stringify(captchaInfo),
- contentType: 'application/json; charset=utf-8',
- dataType: 'json',
- success: function (msg) {
- if (msg) {
- $('#myForm').trigger("submit", [true]);
- }
- else {
- helpers.setCaptcha("captcha");
- }
- },
- error: function (req, status, error) {
- alert("error: " + error);
- helpers.setCaptcha("captcha");
- },
- });
- }
- });
Theoretically this should work but no...
Can you have any idea?
Thanks in advance