1

The response I'm getting back from PHP using an AJAX call:

$.ajax({
 url: 'getit.php',
 type: 'POST',
 dataType: 'json',
 data: {id_token: my_token},
 success: function(data) {
 //stuff
 }
 });

gives me something like this when I console.log it:

email: "[email protected]"
email_verified: true
first_name: "Bob"
permissions: Object
 client_1001: Object
 client_id: "121434"
 role: "full"
 table_name: "5tyyd"
 client_1002: Object
 client_id: "45638"
 role: "full"
 table_name: "df823"

If I do something like this:

$('.last_name').text(data.first_name);

and

<div class="last_name"></div>

This gives me back Bob just as expected.

What I need to get is a list of permissions (e.g., client_1001) and the pieces of data under each permission. I can't figure out how to do though.

This is where I'm stuck:

$('.last_name').text(data.permissions.WHATGOESHERE?);

I need to fill in the WHATGOESHERE? part. It's basically an object in an object, but I'm not sure how to parse it.

asked Feb 16, 2015 at 3:42
1

1 Answer 1

2

As you're using jQuery, give this a try :

$.each(data.permissions, function (index, value) {
 console.log(index); // "client_0001"
 console.log(value.table_name); // "5tyyd"
});

The idea is to iterate through the response, as if you were using foreach() in PHP.

answered Feb 16, 2015 at 3:51
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.