Welcome Guest, Not a member yet? Register   Sign In
Using Ajax to update Multiple DIVS from one controller
#1

[eluser]cblosser[/eluser]
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?

Thanks,

Chris
#2

[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:
Code:
$return['first'] = 'First div stuff';
$return['second'] = 'For the second div';
            
echo json_encode($return);

Javascript (using prototype):
Code:
new Ajax.Request(url, {
    method: 'post',
    onComplete: function(dumptruck) {
        var json = dumptruck.responseText.evalJSON(true);
        $('firstdiv').update(json.first);
        $('seconddiv').update(json.second);
    }
});

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




Theme © iAndrew 2016 - Forum software by © MyBB