code inside php file:
$variable1 = array( 'variable1' => "$variable1" );
$variable2 = array( 'variable2' => "$variable2" );
echo json_encode ($variable1);
code inside main page:
<span id="variable1"></span>
<span id="variable2"></span>
I am trying to make it so it echos both variables in their spans.
doing 2 echos does not work, but the single as coded above works
using the jquery form plugin for this.
If the PHP is fetched w AJAX, then you must create one JSON object with both variables:
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
datathen you can access the 2 variables withdata.variable1anddata.variable2…. like this:Of course, if you’re on the same page, you can use pure PHP: