Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript获取有效代码时出错_Javascript_Ajax_Json_Error Handling - Fatal编程技术网

JavaScript获取有效代码时出错

JavaScript获取有效代码时出错,javascript,ajax,json,error-handling,Javascript,Ajax,Json,Error Handling,加载JSON文件的JavaScript代码出错: function loadJSON(){ var xmlhttp; if (window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = funct

加载JSON文件的JavaScript代码出错:

function loadJSON(){
    var xmlhttp;
    if (window.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            j = JSON.parse(xmlhttp.responseText);
                    //I get the "Uncaught SyntaxError: Unexpected token }" error on the line above
            jsonLoaded = 1;
            init();
        };
    };
    xmlhttp.open("GET", "things.json", true);
    xmlhttp.send();
};
为什么会出现此错误?几个小时前,同样的脚本还在运行


谢谢

尝试打印
xmlhttp.responseText
然后再尝试
JSON.parse()。我怀疑它是否是您所期望的。@JonathonReinhart好的,我会试试。@JonathonReinhart它可能只是无效的JSON,因为它正在加载文件。