I want to update two divs with one ajax call with json encode outside php marks. I am familiar with Update two divs with one AJAX response but would it be possible to do something similar but with data outside < php ?>
Instead of echo-ing ajax response i've closed php and used regular html like for example here is code server side:
<?php
//here some code that cheks some stuff
var $somvariable="Ipsum";
?>
<p>Lorem Lorem <?php echo $somvariable ; ?></p>
and then in ajax function I update div like:
success:function(data, textStatus, jqXHR)
{
//data: return data from server
$('#divid').html(data);
}
Now imagine i have to use json_encode to create two variables that update two divs so i can do:
success:function(data, textStatus, jqXHR)
{
$('#dividone').html(data.one);
$('#dividtwo').html(data.two);
}
and my code outside < ?php ?> is to big and would be too time consuming to convert it to normal string. How can I make this work? My guess is use raw json but how? obviously nothing like:
<?php
echo json_encode(array(
'one' => '?><p>Lorem Lorem <?php echo $somvariable ; ?></p><?php',
'two' => '?><p>Lorem <?php echo $somvariable2 ; ?></p><?php'
));
?>
Will not work but I hope it shows what i try to accomplish.