I am attempting to access a JSON object from a PHP script that looks like:
$results = array(
'total' => $all_totalf,
'error' => $all_errorsf,
);
echo json_encode($results);
The JSON object looks like:
{"total":"11,644","error":"179"}
Then I have a jQuery script that looks like:
var url = "get_control_data.php";
var total;
$.getJSON(url, function (data) {
var total = data.total;
});
document.getElementById("total").innerHTML = total;
I am stuck because total is being returned as "undefined". Does anyone know what I am doing wrong?