Hi, can someone point me in the right direction with JSON.
I get this to work correctly:
File creates json:
echo json_encode(array("upsGround" => "6.95", "ups2DayAir" => "12.95", "upsNextDayAir" => "29.95"));
The following function sets output (populating text fields)
function setOutput(){
if(httpObject.readyState == 4){
alert(httpObject.responseText);
var response = eval("(" + httpObject.responseText + ")");
if (response) {
upsGround = response.upsGround;
document.NML_Order.upsGround.value= response.upsGround;
ups2DayAir = response.ups2DayAir;
document.NML_Order.ups2DayAir.value= response.ups2DayAir;
upsNextDayAir = response.upsNextDayAir;
document.NML_Order.upsNextDayAir.value= response.upsNextDayAir;
}
}
}
When I try to generate the JSON from my file to get dynamic values for rates
(this isn't the whole thing)
if ($ups_rates) {
$ct= count($ups_rates);
for($i=0;$i<$ct;$i++){
if($ups_service[$ups_rates[$i][service]] == "Ground") {
$upsGround = sprintf("%01.2f", $ups_rates[$i][total]) * $fixWeight * 1;
}
if($ups_service[$ups_rates[$i][service]] == "TwoDayAir") {
$ups2DayAir = sprintf("%01.2f", $ups_rates[$i][total] * $fixWeight) * 1;
}
if($ups_service[$ups_rates[$i][service]] == "NextDayAir") {
$upsNextDayAir = sprintf("%01.2f", $ups_rates[$i][total]) * $fixWeight * 1;
}
}
echo json_encode(array("upsGround" => $upsGround, "ups2DayAir" => $ups2DayAir, "upsNextDayAir" => $upsNextDayAir));
}
I get:
syntax error, ()
I now know that it's because it's returning more than just the json my question is how do I get only the json out of my dynamic file?