Fetch API cannot load file:///android_asset/www/xx/xxx.json. URL scheme “file” is not supported

北城余情 提交于 2019-12-05 13:05:54

https://github.com/github/fetch/pull/92#issuecomment-140665932

You may use XMLHttpRequest for loading local assets.

I used the code below to sidestep a similar issue with fetch(). I didn't want to use the code from the link in Jan's answer because I didn't want to manually stream the data (the response object resulting from that code didn't have a responseText property).

function fetchLocalResource(url) {        
    const req = new XMLHttpRequest();    
    req.onload = function() {
        const text = req.responseText;  
        // Do something with text...
    };    
    req.open('GET', url);
    req.send();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!