我正在测试mozilla(https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)的获取示例。
我的“fetchtest”功能应该返回google.com源代码......但它无效。
你能帮我吗?
console.log(fetchtest('http://google.com'));
function fetchtest(url) {
fetch(url).then(function(response) {
if(response.ok) {
response.text().then(function(text) {
//console.log(text); // is working
return text; // isn't working
});
} else {
return 'Network response was not ok.';
}
}).catch(function(error) {
return 'There has been a problem with your fetch operation: ' + error.message;
});
}