Answer the question
In order to leave comments, you need to log in
How to execute form.submit on ajax success?
Tell me, please, how can I execute form.submit inside the success of the Ajax request? If it matters, then the ajax request is made using the BX.ajax method. The browser (Mozilla) when trying to submit the form writes that Firefox blocked one pop-up window from the site.
$('#myform').validate({
debug: true,
rules : {
email : {
required : true,
email : true
}
},
messages : {
email : {
required : '<div class="input-error">Введите, пожалуйста, ваш e-mail</div>',
email : '<div class="input-error">Некорректный e-mail</div>'
}
},
submitHandler: function(form) {
//Получим данные формы
var data = $(form).serialize();
console.log(data);
//Выполним ajax запрос
BX.ajax({
url: 'myajax.php',
method: 'POST',
data: data,
dataType: 'json',
onsuccess: function(response) {
if (response.status == 'OK') {
$(form).find('input[name="orderNumber"]').val(response.orderNumber);
console.log($(form));
form.submit();
}
}
});
}
});
console.log($(form));works and produces the correct result.
Answer the question
In order to leave comments, you need to log in
Thanks to all. Found a solution.
You need to tell ajax that the request is synchronous using a parameter
async: false. With a successful request for some variable, we set
true.
form.submit();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question