Using Ajax to update Multiple DIVS from one controller

I have a controller function that makes changes to two divs. Currently I am using Projax to update a single div. My question is how to update 2 separate divs using one function?



[eluser]Pascal Kriete[/eluser]
I assume you mean view, not controller. Your javascript should not be in the controller (the backend obviously will be though).

I've never used projax, but generally to update multiple items you need to do something like this (only works in php5):
PHP Backend:
$return['first'] = 'First div stuff';
$return['second'] = 'For the second div';
echo json_encode($return);

Javascript (using prototype):
new Ajax.Request(url, {
    method: 'post',
    onComplete: function(dumptruck) {
        var json = dumptruck.responseText.evalJSON(true);

So basically: You echo a json object - eval it (carefull there are security risks) - and then treat it like any old object

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.