Adam
Adam

Reputation: 1971

PHP to JQUERY - Accessing JSON Elements

I'm sending the following from PHP to JSON

 print json_encode(array('success' => TRUE, 'status' => array('username' => 'valid', 'password' => 'valid', 'token' => $tokenhash)));

I can access success in JQUERY like this for example:

        function (data) {
            alert(data.success);

How can I access token? I tried alert(data.success.token); Note: just using alert to see if I can hook into the required value.

Is there a syntax similar to data.success that I can use for token?

thx

Upvotes: 0

Views: 50

Answers (2)

Pierre de LESPINAY
Pierre de LESPINAY

Reputation: 46178

Isn't it data.status.token that you are looking for ?

Upvotes: 1

actionshrimp
actionshrimp

Reputation: 5229

data.success is just grabbing the success key from your array. Looks like you want data.status.token.

Upvotes: 1

Related Questions