1 回答
TA贡献1871条经验 获得超13个赞
不跨域或者可以跨域的话
function getMime(dist) {
return new Promise(function(resolve,reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', dist);
xhr.responseType = 'blob';
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
resolve(xhr.response.type);
}else{
reject();
}
}
}
xhr.send();
})
}
getMime().then(function(type){
console.log(type)
},function(){
console.log('rejct')
});
添加回答
举报