I have a json like this :
{
"One\-test": {
"name" : "One\-test",
"link" : "xxx"
},
"Two\-test": {
"name" : "Two\-test",
"link" : "yyy"
}
}
and in my javascript file I use a jQuery call
var myJson;
jQuery.getJSON('path/myJson.json', function (data) {
myJson = data;
});
Unfortunately the call doesn't succeed, in the sense that myJson = data is not executed (I tried to put a console message just before the statement but it is not executed) and the variable myJson is still undefined (I waited for the end of the call with a $.when statement and I printed out myJson). Most likely the issue could be the format of names One\-test and Two\-test (chars '\' and '-' ), because the path is correct (I'm pretty sure). I cannot change those names, then I have to think about something else. Any idea? I tried with an ajax call like this :
function getJson(myJson){
$.ajax({
type: "GET",
url: "path/myJson.json",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success:
function(data) {
myJson = data;
}
});
}
but result is still the same.
EDIT
If I try to execute the same code with :
{
"Onetest": {
"name" : "One\-test",
"link" : "xxx"
},
"Twotest": {
"name" : "Two\-test",
"link" : "yyy"
}
}
it succeed. This is another proof of "bad format"
var myJson = data;path? where does it point to? external domain? same domain, different folder? is ithttporfileprotocol that you are trying to access?file://URLs doesn't work in some browsers.