我正在尝试使用ajax请求通过fiield进行搜索。这是我的控制器:
public function actionUpdateAjax()
{
$model=new DeliveyInfo();
$rows =Yii::app()->db->createCommand()
->select('fio, date, status')
->from('delivey_info')
->where('code=:code', array(':code'=>$_POST['word']))
->queryRow();
$this->renderPartial('_ajaxContent',array(
'model'=>$model,'rows'=>$rows,
));
}
这是我使用ajax的视图:
<?php
/* @var $this DeliveyInfoController */
/* @var $model DeliveyInfo */
?>
<div id="info"></div>
<p>
<input id="word" type="text" name="word" />
<input id="YII_CSRF_TOKEN" type="hidden" name="YII_CSRF_TOKEN" />
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
</p>
<?php
Yii::app()->clientScript->registerScript('find', "
$('.search-button').click(function(){
var url = '/deliveyInfo/UpdateAjax';
var word = $('#word').val();
$.ajax({
url: url,
dataType: 'json',
type: 'POST',
data: {
word: word,
'YII_CSRF_TOKEN' : '" . Yii::app()->request->csrfToken . "'
},
})
});
");
?>
我在控制台中回答但为什么_ajaxContent视图在renderPartial之后没有显示?