Answer the question
In order to leave comments, you need to log in
Yii2. How does pjax (or is it just AJAX) work with data-pjax="0" and data-method and data-confirm?
I can not understand how PJAX / AJAX manages to work when it is disabled on the delete button in the standard GridView. I rewrote the controller action as follows:
public function actionDelete($id, $productId = null)
{
$this->findModel($id)->delete();
list($searchModel, $dataProvider) = $this->prepareDataProvider($productId);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
<a href="/catalog/1/variation/3/delete" title="Удалить" data-confirm="Вы действительно хотите удалить данную запись?" data-method="post" data-pjax="0"><span class="glyphicon glyphicon-trash"></span></a>
X-PJAX:true
X-PJAX-Container:#variationsListPjax
X-Requested-With:XMLHttpRequest
Answer the question
In order to leave comments, you need to log in
I think I figured it out myself =)
It's all about the presence of a tabular form, which just has data-pjax. The algorithm turns out like this.
The link/button, when processing the data-method, looks for the nearest form, if it finds it, it applies all actions to it, if it does not find it, it creates a new form.
Changes the action and method for the given form to those set accordingly.
Well, then everything is simple. Thanks chrome debugger.
As a result, in order to achieve AJAX behavior for data-method and data-confirm, you need to wrap such a link in a form with data-pjax set. A perversion of course, but so far the developers have not done anything better.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question