Difference between #1 and #2 of Update content in AJAX with renderPartial

unchanged
Title
Update content in AJAX with partialRender
unchanged
Category
Tutorials
unchanged
Tags
changed
Content
The most easy way to update content in AJAX is to use the partialRender method.

For this exemple I have three files: a controller (HelloWorldController.php) and
two views (index.php and _ajaxContent.php)

<br />
#### controllers/HelloWorldController.php
~~~
[php]
class HelloWorldControllerHelloController extends
CController
{
	public function actionIndex()
	{
		$data = array();
		$data["myValue"] = "Content loaded";
		
		$this->render('index', $data);
	}
	
	public function actionUpdateAjax()
	{
		$data = array();
		$data["myValue"] = "Content updated in AJAX";
		
		$this->renderPartial('_ajaxContent', $data, false, true);
	}
}
~~~

The actionIndex set myValue to "Content loaded" and this variable is
passed to the view "index.php" and to "_ajaxContent.php"

<br />

#### views/helloWorld/index.phpviews/hello/index.php
~~~
[php]
<div id="data">
   <?php $this->renderPartial('_ajaxContent',
array('myValue'=>$myValue)); ?>
</div>

<?php echo CHtml::ajaxButton ("Update data",
                              CController::createUrl('hello/UpdateAjax'), 
                              array('update' => '#data'));
?>
~~~

The ajaxButton call "actionUpdateAjax" and the returned data are
inserted in the div "data"

<br />

####
views/helloWorld/_ajaxContent.phpviews/hello/_ajaxContent.php
~~~
[php]
<?php echo $myValue ?>
~~~

Display $myValue

<br />

Now, run index.php?r=helloWorldindex.php?r=hello

Enjoy!