{"id":2265,"date":"2022-08-30T15:23:25","date_gmt":"2022-08-30T15:23:25","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/ajax-content-not-be-loaded-what-is-wrong-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:23:25","modified_gmt":"2022-08-30T15:23:25","slug":"ajax-content-not-be-loaded-what-is-wrong-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/ajax-content-not-be-loaded-what-is-wrong-collection-of-common-programming-errors\/","title":{"rendered":"ajax content not be loaded, what is wrong?-Collection of common programming errors"},"content":{"rendered":"<p>I want to load some data from a json file, but the content doesn&#8217;t show up and also the browser console doesn&#8217;t return any error. Here&#8217;s the script:<\/p>\n<pre><code>(function($){\n  $(window).load(function(){\n    $.getJSON('.\/assets\/js\/data.json', function(datas){\n        console.log(datas);\n    }); \/\/get JSON\n  }); \/\/window.load\n});\n<\/code><\/pre>\n<p>And am calling the script file like:<\/p>\n<pre><code>    \n<\/code><\/pre>\n<p>What could be wrong?<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8211;more info about issue<\/p>\n<p>when i use $(function(){}) AND $(window).load() chrome dont return any error in console, but the data.json not issued in network tab. and when i don&#8217;t use $(function(){}) AND $(window).load() the data.json is issued but cant load and the chrome return below errors: <img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/cIPfY.png\" \/><\/p>\n<ol>\n<li>\n<p>oh god KILL me, all of this issue happened for only a brain crash. i just missed to remove a &#8220;,&#8221; in the data.json.<\/p>\n<p>thanks to all for answers.<\/p>\n<\/li>\n<li>\n<p>If you assets folder is in root then change you code to(remove leading dot(.)) change &#8216;.\/assets\/js\/data.json&#8217; path to &#8216;\/assets\/js\/data.json&#8217;<\/p>\n<pre><code>    (function($){\n      $(window).load(function(){\n          $.getJSON('\/assets\/js\/data.json', function(datas){\n          console.log(datas);\n        }); \/\/get JSON\n      }); \/\/window.load\n    });\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Remove function($) then try it like below:<\/p>\n<pre><code>$(window).load(function(){\n    $.getJSON('.\/assets\/js\/data.json', function(datas){\n        console.log(datas);\n    }); \/\/get JSON\n  });\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-05 09:40:46. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I want to load some data from a json file, but the content doesn&#8217;t show up and also the browser console doesn&#8217;t return any error. Here&#8217;s the script: (function($){ $(window).load(function(){ $.getJSON(&#8216;.\/assets\/js\/data.json&#8217;, function(datas){ console.log(datas); }); \/\/get JSON }); \/\/window.load }); And am calling the script file like: What could be wrong? &#8212;&#8212;&#8212;&#8212;&#8211;more info about issue when [&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-2265","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2265","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=2265"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2265\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}