Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving value from nested JSON object using jQuery .ajax function
    text
    copied!<p>Let's say I have a JSON object returned from a different domain as follows (This originally contains fairly big volume of data so I omitted the irrelevant parts while keeping its structure intact):</p> <pre><code>{ "query": { "count": 1, "created": "2013-10-08T21:06:49Z", "lang": "en-US", "results": { "quote": { "symbol": "GOOG", "Ask": "854.63", "AverageDailyVolume": "1837530", "PreviousClose": "865.74" } } } } </code></pre> <p>Although I feel fairly comfortable working with JSON, I'm only beginning to learn the nuts and bolts of the jQuery .ajax function for interacting with JSON. I wrote very basic bits of code (below) just to ensure I can retrieve the JSON object and extract one or more values from it:</p> <pre><code>$.ajax({ type: "get", cache: false, dataType: "jsonp", url: "http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in ('" + source + "') &amp;format=json&amp;diagnostics=true&amp;env=http://Fdatatables.org/alltables.env&amp;callback=?", success: function(data) { console.log(data.query.results.quote.symbol); // expected output is "GOOG" } }); </code></pre> <p>When I run above code in Firefox, I get <code>TypeError: data.query is undefined</code> error in the browser console. I noticed that there are several questions already posted that are similar to what I am asking here but haven't found anything that sufficiently addresses this issue - at least from my understanding.</p> <p>Any advice/tips will be much appreciated. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload