Answer the question
In order to leave comments, you need to log in
How to display view on ajax request so that the form works on it?
I want to make the registration form appear on the site with Ajax when a button is clicked.
It turns out I need to display a view with a form on top of the index
Here is the js code when the register button is pressed
let regButton = document.querySelector('#reg_button');
regButton.onclick = function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "site/reg",
success: function (response) {
$('#response').html(response)
},
error: function (response) {
console.log(response)
}
});
};
public function actionReg()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
$model = new RegForm();
return $this->renderAjax('reg', compact('model'));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question