Suppose the following directory structure:
/web
example.html
example.js
/example.json
I open example.html with my browser and it runs example.js, which tries to load the data in example.json synchronously using the following call:
$.ajax({url: "file:///example.json",
dataType: "json",
async: false,
success: function(data) {
console.log(data)
},
error: function(request, status, error) {
console.log(request);
console.log(status);
console.log(error);
}
});
This results in an error with message "Access to restricted URI denied" and error code 1012. So far, I have taken a look at Access to restricted URI denied“ code: ”1012 - Cross domain Ajax request and Access to restricted URI denied code: 1012. The first link suggested that I use jQuery's getJSON method, but this method only works asynchronously. The second link suggests some sort of JSONP callback, but I haven't been able to understand how exactly these work.
Note that this problem easily goes away if I move example.json to /web/example.json, but I would like to avoid this due to some circumstances of my actual problem (what I presented here is a simplification of my actual problem).
EDIT: I am trying this JSONP code, but I am still running into the same error:
$.ajax({url: "file:///example.json",
dataType: "jsonp",
success: function(data) {
console.log(data)
},
error: function(request, status, error) {
console.log(request);
console.log(status);
console.log(error);
}
});