Jijgee
(Davaahuu J)
November 28, 2012, 3:29pm
1
I have ajaxLink which send request to action and action render partially view.And the When response come back, i show the response on the cjuidialog.
Here is the ajaxLink.
CHtml::ajaxLink(CHtml::image(Yii::app()->theme->baseUrl."/images/score.png"), array("game/score"),
array(
"type"=>"post",
"data"=>array("id"=>$data["id"]),
"success"=>"js:function(data){ $('#mydialog'.html(data); $("#mydialog").dialog('open');}"
));
Here is action.
public function actionScore()
{
if(Yii::app()->request->isAjaxRequest)
{
$model= $this->loadModel($_POST['id']);
echo $this->renderPartial('manageScore', array("model"=>$model), false, true);
}
}
Here is the view which is rendered partially for ajax request as a response.
Another ajaxLink is in the view. Problem is that when the first ajax request to display dialog is sent, the another ajax request(CHtml::ajaxLink(“Cancel”, …)) in the view is also sent together. I don’t know why. Second ajax request is supposed to sent when click on the link. But it is sent without clicking. How do I prevent from send ajax request?
div class="gamePartTable">
<div>
<ul>
<li>
<?php echo CHtml::ajaxLink("Cancel", array('game/cancel'),
array(
'data'=>array('id'=>$model->id),
'type'=>'post',
'success'=>'js:function(data){alert(data);}'
));?>
</li>
<li>
<a href="#">Give up</a>
</li>
</ul>
</div>
</div>
seenivasan
(Chellamnivas)
November 28, 2012, 7:12pm
2
Dear Jijgee
I hope the following is helpful.
Try to assign different id s in html options in both ajax links .
Else both will have id of yt0 set by Yii.
Regards.
Jijgee
(Davaahuu J)
November 29, 2012, 6:05am
3
seenivasan:
Dear Jijgee
I hope the following is helpful.
Try to assign different id s in html options in both ajax links .
Else both will have id of yt0 set by Yii.
Regards.
Dear seenivasan
It still doesn’t work after assigning different id s. If remove the ajaxLink in the view. it works well. But if I add ajaxLink in the view, dialog doesn’t open. Any ideas?
seenivasan
(Chellamnivas)
November 29, 2012, 4:43pm
4
Dear Jijgee
I tried to simulate your scenario.
This is what I have done. This is working.
views/test/one.php
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog',
'options'=>array(
'disabled'=>true,
'title'=>'Test',
'autoOpen'=>false,
'width'=>600,
'show'=>'fadein',
'modal'=>true,
),
));
?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
<?php
echo CHtml::ajaxLink('click',array('test/ajax'),array(
'success'=>'js:function(data){
$("#mydialog").html(data);
$("#mydialog").dialog("open");}'
),array('id'=>'one'));
?>
views/test/two.php
<?php
echo CHtml::ajaxLink('Cancel',array('test/two'),array(
'success'=>'js:function(data){alert(data);}'
),array('id'=>'two'));
?>
TestController.php
<?php
class TestController extends Controller
{
public $layout='//layouts/column2';
public function actionOne()
{
$this->render('one');
}
public function actionTwo()
{
echo "hello";
}
public function actionAjax()
{
$this->renderPartial('two',array(),false,true);
}
}
Regards.
Jijgee
(Davaahuu J)
December 1, 2012, 3:55am
5
seenivasan:
Dear Jijgee
I tried to simulate your scenario.
This is what I have done. This is working.
views/test/one.php
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog',
'options'=>array(
'disabled'=>true,
'title'=>'Test',
'autoOpen'=>false,
'width'=>600,
'show'=>'fadein',
'modal'=>true,
),
));
?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
<?php
echo CHtml::ajaxLink('click',array('test/ajax'),array(
'success'=>'js:function(data){
$("#mydialog").html(data);
$("#mydialog").dialog("open");}'
),array('id'=>'one'));
?>
views/test/two.php
<?php
echo CHtml::ajaxLink('Cancel',array('test/two'),array(
'success'=>'js:function(data){alert(data);}'
),array('id'=>'two'));
?>
TestController.php
<?php
class TestController extends Controller
{
public $layout='//layouts/column2';
public function actionOne()
{
$this->render('one');
}
public function actionTwo()
{
echo "hello";
}
public function actionAjax()
{
[code]$this->renderPartial('two',array(),false,true);
}
}
[/code]
Regards.
Same as mine. But did not work for me. So I changed renderPartial like following.
$this->renderPartial('two',array(),false,false);
By setting processout parameter to false, ajax requests in the view are not triggered.
setting the id in htmlOptions did the trick to avoid multiple ajax requests - finally!!!
Thank you seenivasan!