我正在尝试使用fetch API获取页面的HTML.这是我的代码.
var quizUrl = 'http://www.lipsum.com/';
var myHeaders = new Headers();
myHeaders.append('Content-Type', 'text/html');
fetch(quizUrl,{
mode: 'no-cors',
method: 'get',
headers: myHeaders
}).then(function(response) {
response.text().then(function(text) {
console.log(text);
})
}).catch(function(err) {
console.log(err)
});
Run Code Online (Sandbox Code Playgroud)
它返回空字符串.任何猜测为什么它不起作用?