在javascript中找不到JSON文件

时间:2014-01-20 17:03:56

标签: javascript json

我正在尝试从javascript加载JSON文件,但即使路径正确,我仍然会收到以下错误

[HTTP/1.1 404 Not Found 2ms]

这是我用来加载它的代码

loadJSON(callback) {
    var xobj = new XMLHttpRequest();
    xobj.overrideMimeType("application/json");
    xobj.open('GET', 'Assets/test.json', true); // Replace 'my_data' with the path to your file
    xobj.onreadystatechange = function () {
        if (xobj.readyState == 4 && xobj.status == 200) {
            // Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
            callback(xobj.responseText);
        }
    };
    xobj.send(null);
}

window.onload = function () {
var canvas = <HTMLCanvasElement> document.getElementById('Can');
context = canvas.getContext('2d');

load = new preload.AtlasLoader();
load.loadJSON(init);


}

function init(response) {
    image2 = JSON.parse(response);
}

提前致谢

1 个答案:

答案 0 :(得分:0)

我在这个帖子中找到了答案:

https://stackoverflow.com/questions/19516829/allow-loading-of-json-files-in-visual-studio-express-2013-for-web

这是IIS的配置问题,你只需要在该问题的答案中添加lnes。