if(typeof fetch === 'function' && typeof window.fetch === 'function') {
// 支持
}
if(typeof fetch !== 'function' || typeof window.fetch !== 'function') {
// 不支持
}
var req = new Request('/data.json', {method: 'POST', cache: 'reload'});
fetch(req).then(function(res) {
return res.json();
}).then(function(data){
console.log(data);
});
credentials
凭证参数
fetch('a.com/api', {credentials: 'include'}).then(function(res) {
// ...
});
或
var req = new Request('/data.json', {method: 'POST', cache: 'reload', credentials: 'include'});
fetch(req).then(function(res) {
return res.json();
}).then(function(data){
console.log(data);
});