小编J D*_*Doe的帖子

为什么await不能在firefox上使用async

基本上我有这个功能

async function get(url){
  const response = await fetch(url);
  const resData = await response.text();
  return resData;
}
Run Code Online (Sandbox Code Playgroud)

然后我接到这个电话

let data = await get(am_url);
Run Code Online (Sandbox Code Playgroud)

该代码在 google chrome 上完美运行,但在 firefox 上,我在调用线路上收到此错误:

语法错误:await 仅在异步函数和异步生成器中有效

这里有什么问题,对于我的一生,我似乎无法在 Firefox 上使用它,并且不明白为什么

例如,如果我在 firefox 和 google chrome 上打开 google.com,然后我转到控制台,并粘贴此代码,在 chrome 上,它将运行,但在 firefox 上,它将抛出我提到的错误

async function get(url){
  const response = await fetch(url);
  const resData = await response.text();
  return resData;
}

let data = await get("http://google.com");
console.log(data)
Run Code Online (Sandbox Code Playgroud)

javascript fetch async-await

3
推荐指数
1
解决办法
4003
查看次数

标签 统计

async-await ×1

fetch ×1

javascript ×1