html网页怎么根据json文件内的路径将在js脚本?

2025-04-16 01:38:02
推荐回答(1个)
回答1:

var req = new XMLHttpRequest();
req.open("cfg.json", true);
req.onreadystatechange = function(){
    if(req.readyState == XMLHttpRequest.DONE){
        var obj = eval("(" + req.response + ")");
        var path = obj.cfg[0].path;
        document.write("");
        // TODO
    }
}
req.send();