If the PHP is fetched w AJAX, then you must create one JSON object with both variables:
<?php
// The PHP page
$variable = array( 'variable1' => "$variable1",
'variable2' => "$variable2" );
// One JSON for both variables
echo json_encode($variable);
?>
And then on the main page, you can access the JSON object and display data from it inside your spans. You can do this as I illustrate, but however you do it, if you put the returned JSON in data
then you can access the 2 variables with data.variable1
and data.variable2
.... like this:
$.getJSON('yourPath/yourPage.php', function(data) {
// Inside your success callback:
$("#variable1").html(data.variable1);
$("#variable2").html(data.variable2);
});
Of course, if you're on the same page, you can use pure PHP:
<?php
$variable = array( 'variable1' => "$variable1",
'variable2' => "$variable2" );
?>
...
<span id="variable1"><?php echo $variable["variable1"]; ?></span>
<span id="variable2"><?php echo $variable["variable2"]; ?></span>