Hi,
I have a problem about ajax request. In my firebug or chrome developer I see that, yes, the ajax request is come back, and it contains the good information, the good admin.php view!
But in my browser doesn’t change my admin view! Here the screenshoot.
Controller:
public function actionAdmin($data =null) {
Yii::app()->language='hu';
if($data==null || empty($data))
{
$data=$_GET;
}
if (isset($data['request_turn']) && $data['request_turn'] === "new") {
// Haven't successed set the actual turn.
if (!Setting::setActualTurn()) {
// Throw new 404 exception.
throw new CHttpException(404, 'The setting of the new turn not supported.');
}
else{
// Pre-insert the teams into the table.
Result::insertTeams();
}
}
$model = new Result('search');
$model->unsetAttributes(); // clear any default values
if (isset($data['Result']))
$model->attributes = $data['Result'];
$this->render('admin', array('model' => $model));
}
public function actionAjaxCheckTurn() {
if(Setting::isSettedTurnsEquals()){
$data = $_GET;
$this->actionAdmin($data);
}
else{
echo json_encode(array("errorMessage"=>"Nem lehetséges, nem lettek véglegesítve!"));
}
}
My View:
<?php
/* @var $this ResultController */
/* @var $model Result */
$this->breadcrumbs=array(
Yii::t('strings','Results') =>array('index'),
Yii::t('strings','Manage'),
);
$this->menu=array(
array('label'=>Yii::t('strings','List Result'), 'url'=>array('index')),
array('label'=>Yii::t('strings','Create Result'), 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#result-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1><?php echo Yii::t('strings','Manage Results'); ?></h1>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'new-turn-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row buttons">
<?php
echo CHtml::ajaxButton(Yii::t('strings','New turn'),Yii::app()->createUrl('result/ajaxCheckTurn'),
array(
'type'=>'GET',
'dataType'=>'json',
'data' => array('request_turn'=>'new'),
//'success'=>'function(data) { alert(data);if(data.errorMessage!=""){ alert(data.errorMessage); }else{alert("emitt");jQuery("#yt2").removeAttr("disabled"); jQuery("#yt2").val("Véglegesítve");} }'
'success'=>'function(data) { if(data.errorMessage!=""){ alert(data.errorMessage); } }'
),array('class'=>'',));
?><?php
echo CHtml::ajaxButton(Yii::t('strings','Finishing'),Yii::app()->createUrl('result/AjaxSetTurnFlag'),
array(
'type'=>'GET',
'data' => array('flag'=>'1'),
'success'=>'function(data) { if(data=="false"){ alert("Mentési Hiba!");}}'
//),(Setting::getActualResultTurn()==1 ? array('disabled'=>'disabled', 'value'=>'Véglegesítve'): array()));
));
?>
</div><!-- new-turn-form -->
<?php $this->endWidget(); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'result-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
array(
'header'=>Yii::t('strings','team_name'),
'name' => 'team_id',
'value'=>'$data->team->name',
),
array(
'header'=>Yii::t('strings','value'),
'name' => 'value',
'type'=>'raw',
'value'=>'CHtml::textField("result-value-$data->id",$data->value, array("class"=>"value-input"))',
),
array(
'header'=>Yii::t('strings','turn'),
'name' => 'turn',
'value'=>'$data->turn',
),
array(
'class'=>'CButtonColumn',
'template'=>'{delete}',
),
array(
'class'=>'CLinkColumn',
'labelExpression'=>'Yii::t("strings","save")',
'urlExpression'=>'"javascript:save($data->id);"',
),
),
)); ?>
<script type="text/javascript">
$("yt1").click(function(){
alert( $("#yt2[disabled]").val() );
});
function save(id){
var resultValue = jQuery("#result-value-"+id).val();
//alert(resultValue);
$.ajax({
url: "<?php echo CController::createUrl("result/ajaxSave"); ?>",
data: { "value": resultValue, "id": id },
success: function(data) { if(data=="false"){ alert("Mentési Hiba!"); jQuery("#result-value-"+id).val('0') } }
});
}
</script>
The process:
-
I click on the "New Turn" ajaxButton
-
In Controller I call the actionAjaxCheckTurn method
-
If everything OK, it call the actionAdmin method
-
Render the admin.php view
But it doesn’t change the view in my browser. In the screenshot you can see that, in browser there is the “old” gridview, and in the request theres is the new gridview (it start with higher ID numbers and “Forduló” = Round number)