0

hi i've a little problem when i load json file from my server, the code that i use is:

function dataLoad(){
    //console.log('loading json...');
    var pathUrl = "public_html/wp-content/themes/turisti/include/main.json";
    var places = [];
    $.ajax({    
      url: pathUrl,
      dataType: 'jsonp',
      timeout: 5000,
      success: function(data, status) {
          console.log("success");
      },
      error: function() {
        console.log("some errors");
      }
    });
}

i call this function on the ready event for the DOM, unfortunately i can load the file, the path is correct i verify that via ssh terminal, but the function call ever the error callbacks, someone have some idea to solve this problem?

ghost
  • 45
  • 1
  • 5

1 Answers1

0
{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

I use above json file as sample and you should able to read json file below code;

function getJsonData() {
            console.log("getJsonData is running...");
            $.ajax({
                url: "/_assets/js/json1.json",
                dataType: "text",
                success: function (data) {

                    var json = $.parseJSON(data);
                    //we have json object here
                    //then you can reach like below
                    console.log("object : " + json.menu);
                    console.log("objects' item : " + json.menu.id);
                }
            });
        }
koca
  • 9
  • 3