{"id":658,"date":"2022-08-30T15:05:01","date_gmt":"2022-08-30T15:05:01","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/json-data-displays-in-console-not-in-browser-javascript-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:01","modified_gmt":"2022-08-30T15:05:01","slug":"json-data-displays-in-console-not-in-browser-javascript-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/json-data-displays-in-console-not-in-browser-javascript-collection-of-common-programming-errors\/","title":{"rendered":"json data displays in console not in browser &#8211; javascript-Collection of common programming errors"},"content":{"rendered":"<p>I have some json data I retrieve from php code by a jquery <code>$.post()<\/code> request. The format is json. But the data is not processed on my brower when the callback function is called<\/p>\n<pre><code>$.post(url_send, data_to_send, function(callback_data){\n      var info = callback_data.info;\n      console.log(callback_data.info);\n      ...\n});\n\ncallback_data = {\"success\":[{\"id\":some_number}],\"info\":\"some_string\"} \n<\/code><\/pre>\n<p>To debug, I noticed that : if I put in this code <code>console.log(callback_data);<\/code> the right json data displays in my console, but if I let <code>console.log(callback_data.info)<\/code>, the console displays <code>'undefined'<\/code>. Could someone explain that?<\/p>\n<p>Edit : in my php I have $reply = array(&#8216;success&#8217; =&gt; $ids,&#8217;info&#8217; =&gt; $info); echo json_encode($reply);<\/p>\n<ol>\n<li>\n<p>callback_data will be in string format you have to convert it to json using eval to use it as an object.. once you do the eval you should have callback_data.info something like this<\/p>\n<pre><code>$.post(url_send, data_to_send, function(callback_data){\n      callback_data = eval('(' + callback_data + ')');\n      console.log(callback_data.info);\n      ...\n});\n<\/code><\/pre>\n<\/li>\n<li>\n<p>The json returned by your php page probably doesn&#8217;t contain a field named &#8220;info&#8221;. So, when you try <code>callback_data.info<\/code>, since there&#8217;s no info, it&#8217;s undefined.<\/p>\n<\/li>\n<li>\n<p>The field is information, it shoud be: callback_data.information<\/p>\n<\/li>\n<li>\n<p>There is not attribute in bject named info in ocallback_data but information use information<\/p>\n<p><strong>Live Demo<\/strong><\/p>\n<pre><code>information = callback_data.information\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:17:23. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have some json data I retrieve from php code by a jquery $.post() request. The format is json. But the data is not processed on my brower when the callback function is called $.post(url_send, data_to_send, function(callback_data){ var info = callback_data.info; console.log(callback_data.info); &#8230; }); callback_data = {&#8220;success&#8221;:[{&#8220;id&#8221;:some_number}],&#8221;info&#8221;:&#8221;some_string&#8221;} To debug, I noticed that : if I [&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-658","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/658","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=658"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/658\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}