Below is the json object that I am working with:
$dati = array(
"data" => array(
'address_complete'=>$data->results[0]->formatted_address,
'address_square'=>$data->results[0]->address_components[1]->long_name,
'location'=>$data->results[0]->address_components[2]->long_name,
'postal_code'=>$data->results[0]->address_components[7]->long_name,
'data_ora'=>$tmp_date
),
"str" => array("n".$i=>$array_db[username]),
"index" => $i
);
I am trying to display the data from str. Here is what I have written:
... success:function(msg){
if(msg){
var j = "n"+2;
$("#location").html(msg.str.j);
}else{
$("#location").html('Not Available');
}
},
However, the output appears empty. It works correctly when I directly reference n2 instead of using variable j in $("#location").html(msg.str.j);. Why does this happen?