ajax content not be loaded, what is wrong?-Collection of common programming errors

I want to load some data from a json file, but the content doesn’t show up and also the browser console doesn’t return any error. Here’s the script:

(function($){
  $(window).load(function(){
    $.getJSON('./assets/js/data.json', function(datas){
        console.log(datas);
    }); //get JSON
  }); //window.load
});

And am calling the script file like:

    

What could be wrong?

————–more info about issue

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’t use $(function(){}) AND $(window).load() the data.json is issued but cant load and the chrome return below errors:

  1. oh god KILL me, all of this issue happened for only a brain crash. i just missed to remove a “,” in the data.json.

    thanks to all for answers.

  2. If you assets folder is in root then change you code to(remove leading dot(.)) change ‘./assets/js/data.json’ path to ‘/assets/js/data.json’

        (function($){
          $(window).load(function(){
              $.getJSON('/assets/js/data.json', function(datas){
              console.log(datas);
            }); //get JSON
          }); //window.load
        });
    
  3. Remove function($) then try it like below:

    $(window).load(function(){
        $.getJSON('./assets/js/data.json', function(datas){
            console.log(datas);
        }); //get JSON
      });