kenjisoul
(Xuyuan8)
December 19, 2013, 8:59am
1
I use ajax request to controller action get value from dropdownlist but can’t not get value??
(I have problem at second dropdownlist.)
view.php
<?php
$this->breadcrumbs = array(
'Check Queue',
);
?>
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'book',
'type' => 'horizontal',
'enableClientValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
))
);
?>
<div class = "control-group">
<label class = "control-label" for = "Customers_C_time">
เวลา
<span class = "required"> * </span>
</label>
<div class = "controls">
<table>
<tr align="center">
<th>ชัวโมง</th>
<th width = 20px></th>
<th>นาที</th>
<th width = 20px></th>
<th>จำนวนที่ว่าง</th>
</tr>
<tr>
<td>
<div id="hour">
<?php
echo $form->dropDownList($model, 'C_time', $this->HH(), array('class' => 'input-small',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Customers/MM'),
'update' => '#Customers_drpMinute',
'data' => array('hour' => 'js:this.value'),
), 'multiple' => true,
'style' => 'height:180px;'
));
?>
</div>
</td>
<td></td>
<td>
<div id="minute">
<?php
echo $form->dropDownList($model, 'drpMinute', array(), array('class' => 'input-small',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Customers/All'),
'update' => '#seats',
'data' => array('hour' => 'js:this.value'),
),
'multiple' => true, 'style' => 'height:180px;'));
?>
</div>
</td>
<td></td>
<td>
<div id="seats"> </div>
</td>
</tr>
<tr>
<td><?php echo $form->error($model, 'C_time'); ?></td>
<td></td>
<td><?php echo $form->error($model, 'drpMinute'); ?></td>
<td></td>
<td></td>
</tr>
</table>
</div>
</div>
<?php
$this->endWidget();
Controller.php
public function actionAll() {
$rs = $_POST['drpMinute']; //if comment this and print_r("hello"); it's work
print_r($rs);
}
lpoolerl
(Rt Vitalmax)
December 19, 2013, 11:40am
2
Update your action like
public function actionAll() {
Yii::log('received', 'info', 'system.fucking.ajax.check');
Yii::log(CVarDumper::dumpAsString($_POST), 'info', 'system.fucking.ajax.check');
$rs = $_POST['drpMinute']; //if comment this and print_r("hello"); it's work
print_r($rs);
}
Do not forget to update a config to get logs!
Then continue debugging
kenjisoul
(Xuyuan8)
December 19, 2013, 5:32pm
3
lpoolerl:
Update your action like
public function actionAll() {
Yii::log('received', 'info', 'system.fucking.ajax.check');
Yii::log(CVarDumper::dumpAsString($_POST), 'info', 'system.fucking.ajax.check');
$rs = $_POST['drpMinute']; //if comment this and print_r("hello"); it's work
print_r($rs);
}
Do not forget to update a config to get logs!
Then continue debugging
Not happen
Loading "log" application component
trace system.CModule 18:25:45.449165
Loading "request" application component
trace system.CModule 18:25:45.450573
Loading "viewRenderer" application component
trace system.CModule 18:25:45.456263
Loading "db" application component
trace system.CModule 18:25:45.458059
Opening DB connection
trace system.db.CDbConnection 18:25:45.458986
Loading "clientScript" application component
trace system.CModule 18:25:46.471138
Loading "assetManager" application component
in C:\xampp\htdocs\book\protected\extensions\yii-debug-toolbar\YiiDebugToolbar.php (92)
in C:\xampp\htdocs\book\protected\extensions\yii-debug-toolbar\YiiDebugToolbar.php (152)
in C:\xampp\htdocs\book\protected\extensions\yii-debug-toolbar\YiiDebugToolbar.php (120)
trace system.CModule 18:25:46.472577
Loading "urlManager" application component
trace system.CModule 18:25:46.484229
Running filter CustomersController.filteraccessControl()
trace system.web.filters.CFilterChain 18:25:46.489135
Loading "user" application component
trace system.CModule 18:25:46.489706
Loading "session" application component
trace system.CModule 18:25:46.490756
Loading "themeManager" application component
trace system.CModule 18:25:46.503954
Loading "widgetFactory" application component
trace system.CModule 18:25:46.505662
Loading "bootstrap" application component
trace system.CModule 18:25:46.521581
Loading "coreMessages" application component
trace system.CModule
lpoolerl
(Rt Vitalmax)
December 20, 2013, 10:07am
4
Haven’t I told you not to forget to update your config? ??
Do it like:
'log' => array(
'routes' => array(
array(
'class'=>'CFileLogRoute',
'levels'=>'info',
'categories'=>'system.fking.ajax.check',
'logFile' => 'fk.info.log',
),
)
),
Then post /protected/runtime/fk.info.log contents here.
kenjisoul
(Xuyuan8)
December 20, 2013, 1:45pm
5
lpoolerl:
Haven’t I told you not to forget to update your config? ??
Do it like:
'log' => array(
'routes' => array(
array(
'class'=>'CFileLogRoute',
'levels'=>'info',
'categories'=>'system.fking.ajax.check',
'logFile' => 'fk.info.log',
),
)
),
Then post /protected/runtime/fk.info.log contents here.
I’m already set all but have not got log file.
kenjisoul
(Xuyuan8)
December 20, 2013, 2:00pm
6
Now I use Firebug tool(firefox plug-in).
I got this error. Why??
Undefined index: drpMinuts
kenjisoul
(Xuyuan8)
December 21, 2013, 8:07am
8
Argent:
try the $_POST["hour"]:
that work, but if I want to pass C_time value from drpMinute dropdownlist ajax how to reference C_time dropdownlist
'data' => array('hour' => 'js:$("#C_time").value', 'minute' => 'js:this.value');
it’s not work
argent
(Argent Hun)
December 21, 2013, 2:48pm
9
kenjisoul:
that work, but if I want to pass C_time value from drpMinute dropdownlist ajax how to reference C_time dropdownlist
'data' => array('hour' => 'js:$("#C_time").value', 'minute' => 'js:this.value');
it’s not work
.val() instead of .value in the jQuery , so:
'data' => array('hour' => 'js:$("#C_time").val()', 'minute' => 'js:this.value');
and then $_POST["hour"] and $_POST["minute"] in the controller.
add id to the dropDownList:
<?php
echo $form->dropDownList($model, 'C_time', $this->HH(), array(
'class' => 'input-small',
'id' => 'C_time',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Customers/MM'),
'update' => '#Customers_drpMinute',
'data' => array('hour' => 'js:this.value'),
), 'multiple' => true,
'style' => 'height:180px;'
));
?>
kenjisoul
(Xuyuan8)
December 22, 2013, 1:05pm
10
Argent:
.val() instead of .value in the jQuery , so:
'data' => array('hour' => 'js:$("#C_time").val()', 'minute' => 'js:this.value');
and then $_POST["hour"] and $_POST["minute"] in the controller.
add id to the dropDownList:
<?php
echo $form->dropDownList($model, 'C_time', $this->HH(), array(
'class' => 'input-small',
'id' => 'C_time',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Customers/MM'),
'update' => '#Customers_drpMinute',
'data' => array('hour' => 'js:this.value'),
), 'multiple' => true,
'style' => 'height:180px;'
));
?>
It’s work. Thank you very much.