Multiple Renderpartial In Controller

Hi all,

I did the tutorial about updating content with AJAX. ( So far everything is working.

When I put more than one renderPartial into actionUpdateAjax() the content on the website only gets updated when the last renderPartial is called. Why is this happening? Can this somehow be avoided so each renderPartial updates the content immediately?

Thanks in advance for any help.


Hi Jonas,

It depends on how you write the ajax function in the view.

When you have called renderPartial(“A”) and renderPartial(“B”) in the controller (server side), then contents “A” + “B” will be received in the view of the user’s browser (client side). But all the received contents may not be used to update the screen. I depends on how you have written the ajax script.

I did it like this:


<div id="log">

   <?php $this->renderPartial('_ajaxContent', array('myValue'=>$myValue)); ?>


"Partial"view (_ajaxContent.php):


echo $myValue;


$data["myValue"] = "Starting Connection... <br />\n";

$this->renderPartial('_ajaxContent', $data, false, true);

// Some code to establish connection....

$data["myValue"] = "Connected. <br />\n";

$this->renderPartial('_ajaxContent', $data, false, true);

It’s like in the example I’ve mentioned above.

I see.

I think it should display

Starting Connection...


in a single shot.

It will not display first

Starting Connection... 

and then change to


It’s a single response.


In the previous post, I thought you are updating 2 different divs with different contents …

If you want to have 2 phases of disyplay, like

1) Starting Connectionn ...

2) Connected.


1) Starting Connectionn ...

2) Starting Connectionn ... Connected.

Then you will have to have 2 pairs of call and response.

Exactly, that’s what I want to achieve. But there must be a way to continously send messages to a div without using a call for each message? Or maybe I missunderstood your answer?

You may want to set a timeout and… repeat the call, or use long polling, HTML5’s websockets, or Server-Sent Events

Thanks for the hints, bennouna. I played around a little bit with SSE, but had some problems as it was always reloading the script… I now solved my information needs with plain old logging. :)

But thanks anyway.