我正在尝试显示从服务器返回的数据,当我查看 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);
});