Answer the question
In order to leave comments, you need to log in
How to make AJAX submit and process data in Yii2 ActiveForm?
Tell me, you need to send Ajax data in ActiveForm after validation and then, after receiving the response, execute the function. The search was unsuccessful.
Answer the question
In order to leave comments, you need to log in
More or less like this:
$form = ActiveForm::begin([
'id' => 'form-input-example',
'options' => [
'onsubmit' => 'sendAjax(this, myAction)'
],
]);
...
var myAction = function (response) {
//Делаем то, что нам нужно с ответом
console.log(response);
}
function sendAjax(form, callback) {
$.ajax({
method: 'post',
url: '/test',
dataType: 'json',
data: $(form).serialize()
}).done(function (response) {
callback(response);
})
//Возвращаем false чтобы форма не отправилась
return false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question