Yii Framework Forum: Ajax Request - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ajax Request Rate Topic: -----

#1 User is offline   Jijgee 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 16-June 12

Posted 28 November 2012 - 10:29 AM

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>


0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 601
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 28 November 2012 - 02:12 PM

Dear Jijgee

I hope the following is helpful.

Try to assign different ids in html options in both ajax links.

Else both will have id of yt0 set by Yii.

Regards.
0

#3 User is offline   Jijgee 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 16-June 12

Posted 29 November 2012 - 01:05 AM

View Postseenivasan, on 28 November 2012 - 02:12 PM, said:

Dear Jijgee

I hope the following is helpful.

Try to assign different ids 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 ids. If remove the ajaxLink in the view. it works well. But if I add ajaxLink in the view, dialog doesn't open. Any ideas?
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 601
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 29 November 2012 - 11:43 AM

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.
0

#5 User is offline   Jijgee 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 16-June 12

Posted 30 November 2012 - 10:55 PM

View Postseenivasan, on 29 November 2012 - 11:43 AM, said:

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users