GlobalFetch

所述 GlobalFetch 接口暴露 fetch 功能,其可被用于请求资源。

fetch('/path/to/resource.json')
    .then(response => {
        if (!response.ok()) {
            throw new Error("Request failed!");
        }
            
        return response.json();
    })
    .then(json => { 
        console.log(json);
    }); 

已解析的值是响应对象。此 Object 包含响应的主体,以及它的状态和标头。