Answer the question
In order to leave comments, you need to log in
How to initialize Pjax in Yii2?
Data is loaded into the modal form via Ajax:
$('[firmmodal]').on('click',function(){
console.log('s');
$.ajax({
type: 'GET',
url: '/firm/update/',
data: {
id: $(this).attr('firmmodal')
},
success: function(data){
$('#firmModalUpdate').html(data);
}
})
})
<?php Pjax::begin(['enablePushState' => false, 'id' => 'firmUpdate']); ?>
<?php $form = ActiveForm::begin(['options' => ['data-pjax' => true]]); ?>
.......
<?= Html::submitButton($model->isNewRecord ? 'Создать' : 'Обновить', ['class' => 'uk-button uk-button-primary', 'data-pjax' => '1']) ?>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
public function actionUpdate($id = false)
{
if($id){
$model = $this->findModel($id);
}else{
$model = new Firm();
}
$this->layout = false;
$model->_save = false;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->_save = true;
}
return $this->render('update', [
'model' => $model,
]);
}
Answer the question
In order to leave comments, you need to log in
www.yiiframework.com/doc-2.0/yii-widgets-pjaxasset.html
asset is present on the page where pjax connects?
I don't understand why there is ajax. Is it not possible to do this through the same pjax?
But I would check where the pjax request is knocking and if there is an error there, I would also increase the timeout, if pjax does not receive a response within timeout (1000ms), it throws a regular get. Maybe that's the thing. Put to check:
Pjax::begin([
'timeout'=>60000
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question