Kto pomoże znaleźć błąd? serwer zwraca mi [Object Object], kod ma na celu kasowanie postów.
$script2 = <<< JS
$(document).ready(function(){
$("button.product-delete").on('click',function(e){
var keys = $('#products-grid').yiiGridView('getSelectedRows');
$.post({
url: '/movie/mass', // your controller action
dataType: 'json',
data: {keylist: keys},
success: function(data) {
//if (data.status === 'success') {
console.log(data)
//}
},
error: function( req, status, err ) {
console.log( 'Something went wrong', status, err );
}
});
});
});
JS;
if (isset($_POST['keylist'])) {
$keys = Json::decode($_POST['keylist']);
if (!is_array($keys)) {
echo Json::encode([
'status' => 'error',
'total' => 0
]);
return;
}
$total = 0;
foreach ($keys as $key) {
$model = Movie::findOne($key);
$total += $model->delete();
}
echo Json::encode([
'status' => 'success',
'total' => $total
]);
echo Json::encode([
'status' => 'error',
'total' => 0
]);
}
return $this->redirect(['movie/index']);