<?php
$id = $model->id;
$this->registerJs(<<<JS
$('#launch-class').on('change', function(){
$.ajax({
url: '/launch/update?id={$id}',
type: 'POST',
data : $(this).val(),
success: function(res){
console.log(res);
},
error: function(){
alert('Error!');
}
});
});
JS
);
?>
Array
(
[2] =>
)
public function actionAjax($id)
{
if( Yii::$app->request->isAjax){
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if($model->save(false)){
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
if( Yii::$app->request->isAjax){
$isValid = $model->validate();
if($isValid){
$model->class = key($_POST);
$model->save(false);
}
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
jquery.js?v=1506282721:9175 POST http://backend.yii2-core.dev/noty/default/index 404 (Not Found)