{"id":1223,"date":"2022-08-30T15:14:26","date_gmt":"2022-08-30T15:14:26","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/jquery-object-undefined-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:14:26","modified_gmt":"2022-08-30T15:14:26","slug":"jquery-object-undefined-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/jquery-object-undefined-collection-of-common-programming-errors\/","title":{"rendered":"jQuery object undefined-Collection of common programming errors"},"content":{"rendered":"<p>Apologies for asking what&#8217;s probably a very obvious question, I&#8217;ve been banging my head against this all day + I&#8217;m very new to JQuery and JavaScript in general.<\/p>\n<p>I&#8217;m running the following:-<\/p>\n<pre><code>\n$(function() {\n$.getJSON(\n  \"http:\/\/query.yahooapis.com\/v1\/public\/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&amp;format=json&amp;env=http%3A%2F%2Fdatatables.org%2Falltables.env&amp;callback=?\", \n  function(data) {\n\n$.each(data.query.results.row, function(index, item){\n    $('#quotes')\n    .append(\n      $('<\/code>')\n        .append($('').text(item.symbol))\n        .append($('').text('$'+item.price))\n      );\n    });\n\n  }\n);\n\n});\n\n<\/pre>\n<p><code>I get object undefined var name, i = 0, length = object.length; from firebug - can anyone help me out?<\/code><\/p>\n<ol>\n<li>\n<p><code>The JSON structure doesn't know a query.results.row, but a query.results.quote instead. This works:<\/code><\/p>\n<pre><code><code>  console.log(data);\n  var quotes = data.query.results.quote;\n    for(var q in quotes){\n        $('#quotes')\n        .append(\n          $('<\/code><\/code>')\n            .append($('').text(q))\n            .append($('').text('$'+quotes[q]))\n          );\n        }\n    });\n<\/pre>\n<p><code>You are not calling a JSON resource, but a JSONP resource. The callback argument of the url should be a function name and you should use $.getScript.<\/code><\/p>\n<pre><code><code>myCallback = function(jsonData){...}    \n$.getScript(\"http:\/\/query.yahooapis.com\/v1\/public\/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&amp;format=json&amp;env=http%3A%2F%2Fdatatables.org%2Falltables.env&amp;callback=myCallback\");\n<\/code><\/code><\/pre>\n<\/li>\n<li>\n<p>From looking at the JSON response, <code>data.query.results.row<\/code> is undefined (though <code>data.query.results<\/code> isn&#8217;t). So you&#8217;re looping over an undefined property.<\/p>\n<p>You may read through the response&#8217;s properties by using <code>console.log(data)<\/code> in your callback. Then, download and install FireBug for Firefox if you haven&#8217;t done so already and check the console.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:10:41. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Apologies for asking what&#8217;s probably a very obvious question, I&#8217;ve been banging my head against this all day + I&#8217;m very new to JQuery and JavaScript in general. I&#8217;m running the following:- $(function() { $.getJSON( &#8220;http:\/\/query.yahooapis.com\/v1\/public\/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&amp;format=json&amp;env=http%3A%2F%2Fdatatables.org%2Falltables.env&amp;callback=?&#8221;, function(data) { $.each(data.query.results.row, function(index, item){ $(&#8216;#quotes&#8217;) .append( $(&#8221;) .append($(&#8221;).text(item.symbol)) .append($(&#8221;).text(&#8216;$&#8217;+item.price)) ); }); } ); }); I get object undefined [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1223","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1223"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1223\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}