我想这样做:
我有2个网格。我想选择 idideya (来自第一个网格)和 idperson (来自第二个网格)并将其发送到 actionGonder()。通过此操作,数据插入到表格。
成功'部分' ajax功能正常工作(每次都正确警告 $ perid 和 ideaid )。但数据不会发送给控制器。
请你帮我们。我需要帮助。谢谢。
最好的问候。
查看文件
<?php
$this->widget('yiiwheels.widgets.grid.WhGridView', [
'id' => 'layiheler-c',
'dataProvider'=>$dataProvider,
'filter' => $filtersForm,
'ajaxUpdate'=>true,
'responsiveTable' => true,
'fixedHeader' => true,
'headerOffset' => 40,
'type' => 'striped bordered',
'columns' => [
[
'name' => 'idideya',
'headerHtmlOptions'=>['width'=>120],
'header' => '#'
],
[
'name' => 'ideyaad',
'headerHtmlOptions'=>['width'=>120],
'header' => 'İdeya adı'
],
[
'name' => 'tarix',
'headerHtmlOptions'=>['width'=>120],
'header' => 'Təqdim olunma tarixi'
],
],
]);
?>
<button id="lrl" style="position: fixed">daxil et</button>
<br><br>
<?php
$this->widget('yiiwheels.widgets.grid.WhGridView', [
'id' => 'ekspertler-c',
'dataProvider' => $dataProvider2,
'filter' => $filtersForm2,
'ajaxUpdate' => true,
'responsiveTable' => true,
'fixedHeader' => true,
'headerOffset' => 40,
'type' => 'striped bordered',
'columns' => [
[
'name' => 'idperson',
'headerHtmlOptions'=>['width'=>120],
'header' => '#'
],
[
'name' => 'adi',
'headerHtmlOptions'=>['width'=>120],
'header' => 'Ad'
],
[
'name' => 'familya',
'headerHtmlOptions'=>['width'=>120],
'header' => 'Soyad'
],
],
]);
?>
<button id="eks" style="position: fixed;left: 69%;top: 11%;">daxil et</button>
<div id="zirrama">
<input type="text" readonly id="idea_text" />
<input type="text" readonly id="person_text" />
</div>
<script>
$siraI;
$siraP;
$("#lrl").click(function (){
$("#layiheler-c tr.selected").each(function () {
$setir = $(this).find('td');
if($setir.length != 0) {
$hazirki = $setir.eq(1).text();
$siraI = $setir.eq(0).text();
// alert($toplam);
// alert($mircalal);
// alert('seçilmiş ideya adı: ' + $hazirki);
$("#idea_text").val($hazirki).before("<input type='text' style='display: none;' id='idea_text' />");
}
});
});
$("#eks").click(function (){
$("#ekspertler-c tr.selected").each(function () {
$setir = $(this).find('td');
if($setir.length != 0) {
$hazirki = $setir.eq(1).text();
$siraP = $setir.eq(0).text();
// alert($siraP);
// alert('seçilmiş ekspert adı: ' + $hazirki);
$("#person_text").val($hazirki).before("<input type='text' style='float: right; display: none' id='person_text' />");
}
});
});
function updatefunc(){
$perid = $siraP;
$ideaid = $siraI;
//alert($perid + " " + " " + $ideaid);
// alert(perid);
$.ajax({
URL: "gonder/perid=.'$perid'./ideaid=.'$ideaid'",
type: "POST",
cache: false,
data: {
'perid': $perid,
'ideaid': $ideaid
},
success:function(data){
alert ($perid + " " + " " + $ideaid); /* this line works fine. it alerts which idea and person I selected. */
},
});
}
</script>
<?php echo CHtml::submitButton('gonder', array('onclick'=>'updatefunc();')); ?>
<?php /* echo CHtml::button('gonder', array('submit' => array('onclick'=>'updatefunc();'))); */ ?>
控制器文件
public function actionGonder ()
{
// die();
echo "fsdfsdfsdfwtgikkyurtretgyuikuytryhjuhytryhk6ujkjyttyuj";
if (isset($_POST['perid']) && isset($_POST['ideaid'])){
$quer = Yii::app()->db->createCommand()
->insert ('mqrup', array(
'idperson'=> $perid,
'idideya'=>$ideaid ));
// var_dump($quer);
}
// die();
$this->redirect(array('umumi'));
}
答案 0 :(得分:0)
试试这种方式
function updatefunc(){
$perid = $siraP;
$ideaid = $siraI;
$.ajax({
Url: <?php echo Yii::app()- createUrl("controllerName/ gonder"),
type: "POST",
data: {
'perid': $perid,
'ideaid': $ideaid
},
success:function(data){
alert (data);
},
});
}