如何从fetch post请求中检索响应数据?



我试图显示从服务器返回的数据,当我在Chrome的开发者窗口中查看网络选项卡时,我可以看到从服务器返回的数据。

我怎么能得到访问它在我的代码下面?

当按钮被点击时调用handleClick方法。

谢谢!

let data;
async function handleClick() {
const url = "http://127.0.0.1:8000/parse"
data  = await fetch(url, {
mode: 'no-cors',
method: "POST",
headers: { 'Content-type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
locale: "en_GB",
text: "Test Message"
})
})
.then(x => x.text())
console.log(data)
}
// Capture in the promise return section
.then(x => {
// Catch the data through the propertiesName. 
// Here properties means your post request's variable name which you are given.
console.log(x.propertiesName);
});

最新更新