ajaxButton problem

Hi, i’m new to yii, and succeeded with the first ajaxButton.

However, i’m trying to press the second button which pops out as well,

and i’m curious why it won’t work.

Nothing happens when i click "Part 2"-button.

views/ajax/index.php


<?php echo CHtml::ajaxButton(

	'Press for Part 1',

	array('ajax/part1'),

	array('update'=>'#part_1'));?>

	

<div id="part_1"></div>

<div id="part_2"></div>

controllers/AjaxController.php


public function actionPart1(){

	if(Yii::app()->request->isAjaxRequest){

		echo "1st part.<br/>";

		echo CHtml::ajaxButton(

			'Press for part 2',

			array('ajax/part2'),

			array('update'=>'#part_2'));

	}

}

	

public function actionPart2(){

	if(Yii::app()->request->isAjaxRequest){

		echo "2nd part.<br/>";

	}}

Check accessRules().

No, this has to be because the ajaxButton is replaced in the first ajax call. This is a delicate topic. Search the forum for similar threads about ajax (no response, multiple responses).

/Tommy

problem is that ajaxButton() normaly outputs the input button field and registers a javascript code that is rendered on the page in the proper script section…

but on ajax call… it outputs the input button field and register a javascript code… but that code is not outputed (cannot be !!!)

So the only solution is to put all the ajaxbuttons you need in the view… show only the first button and hide all the other… then on ajax complete show the next button…

something like this should work:

view.php




<?php echo CHtml::ajaxButton(

    	'Press for Part 1',

    	array('part1'),

    	array('complete'=>'function(){jQuery("#id2").show();}','update'=>'#part_1')); ?>


<div id="part_1"></div>


<?php echo CHtml::ajaxButton(

		'Press for part 2',

		array('part2'),

		array('update'=>'#part_2'),

		array('id'=>'id2','style'=>'display:none')); ?>


<div id="part_2"></div>



controller




	public function actionPart1()

	{

		if(Yii::app()->request->isAjaxRequest){

			echo "1st part.<br/>";

		}

	}


	public function actionPart2()

	{

	    	if(Yii::app()->request->isAjaxRequest){

		    	echo "2nd part.<br/>";

		}

	}



That makes sense. I tried the code and it worked, thanks! :)