0

I managed to get the JSON array into (look http://yrs2013.bugs3.com/mpapp/getSTORY.php?url=http%3A%2F%2Fcontent.guardianapis.com%2Fsearch%3Fq%3DJohn%20Stevenson%20mp%26page-size%3D3%26format%3Djson there for the array details), Javascript as a JS object - however now when i try and call a piece of data from the array it comes back as 'undefined'.. Any tips? :)

JS Code:

$.getJSON('getSTORY.php?url='+ url2, function(response) 
console.log(response);
//logs the response, comes up as object in the log;
var e = response.status;
//when e is logged it just says 'undefined' 
console.log(e);

In the log the object looks like drop down menus, which is different to my previous attempts of similar things as they came back from the PHP as text. I have tried JSON.parse but however that came back with the undefined o error! :l any help gratefully accepted! Thanks!

1 Answer 1

1

By looking at your JSON structure, I believe you need response.response.status. The first response is a variable holding your whole object, which contains a single response property with status inside (as well as results, etc).

3
  • thank you this works perfectly for status! However whenever I select to try to get the data in results section, for example "webTitle", the error comes as "cannot read property'0' of undefined... the code i use is " var e = response.response.results.id[0].webTitle" Any ideas? thanks!
    – Reality
    Commented Aug 8, 2013 at 22:24
  • EDIT: think ive got it aha! :)
    – Reality
    Commented Aug 8, 2013 at 22:26
  • See stackoverflow.com/questions/11922383/…, it's all there @Reality
    – bfavaretto
    Commented Aug 8, 2013 at 22:26

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.