gpt4 book ai didi

php - 通过ajax向 Controller 发送参数

转载 作者:行者123 更新时间:2023-11-29 23:53:08 25 4
gpt4 key购买 nike

我想这样做:

我有 2 个网格。我想选择 idideya (来自第一个网格)和 idperson (来自第二个网格)并将它们发送到 actionGonder()。通过此操作,数据将插入到表中。

ajax函数的成功“部分”工作正常(它每次都会正确地提醒$peridideaid)。但数据不会发送到 Controller 。

请大家帮帮我。我需要帮助。谢谢。

致以诚挚的问候。

view file

<?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();'))); */ ?>

controller file

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'));
}

最佳答案

试试这个方法

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);
},
});
}

关于php - 通过ajax向 Controller 发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25511625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com