Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I created an array in php (as part of an ajax response) . I would now like to convert this array into a javascript array of objects. How can I do this please?

My php array (please not this is wordpress php):

$fortot2 = 5;
$fortot3 = 2;

if (is_numeric($numwelds) && is_numeric($numconwelds))
{
    $total['tot1'] = $numwelds + $numconwelds + $mpcountrys ;
    $total['tot2'] = $numwelds + $numconwelds + $fortot2 ;
    $total['tot3'] = ($numwelds + $numconwelds) + $fortot2 / $fortot3; 
    $response = json_encode($total);
    header("Content-Type: application/json");  
    echo $response;

Now, how can I convert this into a javascript array of objects, once the json has been encoded?

share
    
Are you getting this with ajax as there's a header and everything ? –  adeneo 2 mins ago
add comment

1 Answer

// responseData is fetched via Ajax-Get
var obj = jQuery.parseJSON(responseData);
alert(obj.property);
share
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.