1

I want to access the request_uuid from my jquery post, but whatever I try doesn't work. I keep getting this error message:

Uncaught TypeError: Cannot read property 'request_uuid' of undefined

This is my array:

Array(
[status] => 201
[response] => Array
    (
        [api_id] => 6562c748-0366-11e5-84ff-22000ac89064
        [message] => call fired
        [request_uuid] => efa98dad-8869-4b72-ad99-a149f914bda5
    ))

I am trying to access it like this:

console.log(data.response['request_uuid']);

How should I access it to get the request_uuid?

4
  • try with this console.log(data.response[0]['request_uuid']); Commented May 26, 2015 at 5:29
  • console.log(data[response]['request_uuid']); Commented May 26, 2015 at 5:31
  • sorry non of the above works! i keep getting an error message Commented May 26, 2015 at 5:39
  • 1
    ok then as Leo answered if both is array then use console.log(data[0].response[0]['request_uuid']); . or update your answer with proper array as answered Commented May 26, 2015 at 5:40

1 Answer 1

1

If your data is an array and your response also, you must to parse the first child(0), before that:

[] = Array():

var data = [{
    'status': 201,
    'response': [{
        'api_id': "6562c748-0366-11e5-84ff-22000ac89064",
        'message': "call fired",
        'request_uuid': "efa98dad-8869-4b72-ad99-a149f914bda5"
    }]
}];

console.log(data[0].response[0]['request_uuid']);
Sign up to request clarification or add additional context in comments.

4 Comments

@jhondano proper array means . array in proper javascript format as leo mentioned in answer :)
@jhondano because your server side sends an array, it means you can have more than one data object, like data[0], data[1] and so on. Same for your response object, like response[0], response[1]. A good way to understand it, is calling console.log(data). Open it on Chrome Dev Tools(or similar) and You'll see when it's an array, and when it's a property of a object
yes thanks for your reply... actually thats exactly what am doing the array posted above is comming from console.log(data). I am confused how can i get my array in proper jquery format?
@jhondano It's actually a Javascript Object which in your case, the serverside responds as an array. Try remember, every time you read Array(), you can have 1 or more, so you must to refer as an array. Maybe this theory will help you spring.io/understanding/JSON

Your Answer

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.