我在gridview中使用了复选框,就像这样
<?php
if(isset($dataProvider) && !empty($dataProvider)) {
echo \yii\grid\GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn',
'header' => 'No.'],
[
'class' => 'yii\grid\CheckboxColumn',
'header'=>'Select',
'checkboxOptions' => function ($model, $key, $index, $column) {
return ['value' => $model->dsItemId];
}
],
[
'label'=>'Category',
'value' => function ($model) {
return $model->getdscategoryName();
},
],
'dsItemName',
'qty',
[
'attribute' => 'image',
'enableSorting' => false,
'format' => 'image',
'value' => function ($model) {
return $model->getImageUrl();
},
],
],
]);
echo Html::submitButton('Save',['id' => 'saveBtn','class' => 'btn btn-danger']);
}?>
当我选择复选框并选择保存按钮时,它将转到下面给出的此功能,
<script>
$( document ).ready(function() {
$('#saveBtn').click(function() {
var idVar = '';
$("input[name='selection[]']").each( function () {
if($(this).is(':checked')) {
if(idVar != '') {
idVar += ',' + $(this).val();
}else {
idVar = $(this).val();
}
}
});
$.ajax({
type: "POST",
url:"<?php echo Yii::$app->urlManager->createAbsoluteUrl(['dsproductitems/setproduct'])?>",
data: { dsItemId : idVar },
success:function(data) {
location.reload();
}
});
});
});
</script>
这里我试图通过ajax将表单重定向到控制器,问题是,程序控制无法进入流动的代码。
$.ajax({
type: "POST",
url:"<?php echo Yii::$app->urlManager->createAbsoluteUrl(['dsproductitems/setproduct'])?>",
data: { dsItemId : idVar },
success:function(data) {
location.reload();
}
});
});
我没弄弄出原因......请帮忙..