I'm using AJAX call and I'm generating this JSON object which is sent back to JavaScript. When I receive it in the JavaScript I'm not able to get values from it.
PHP:
echo json_encode(array("results" => array(array("user" => $member['user']),array("company" => $member['company']))));
JS:
success: function(response)
{
for(var i = 0;i < response.results.length; i++)
{
sessionStorage.setItem('user',response.results[i].user);
sessionStorage.setItem('company',response.results[i].company);
}
}
I'm not able to read any values from the response that I receive.
Response that I get is in this format:
{"results":[{"user":"David"},{"company":"something"}]}
What would be the proper way of reading this JSON object?
{"results":[{"user":"David", "company":"something"}]}forloop never executing or what is the problem?dataType: 'json'option in the Ajax call.