1 回答
TA贡献1844条经验 获得超8个赞
您可以通过标志限制并发请求
var data = null,
isLoading = false, // perhaps you need to make this persistent depending on your overall architecture
if (!isLoading)
{
data = prompt("Enter your data here");
}
if (data !== null || data !== ''){
isLoading = true;
fetch('http://localhost:3000/post', {
method: 'POST',
body: JSON.stringify({
data: data
}),
headers: {
'Content-Type': 'application/json',
}
}).then((res) => {
console.log("wait for whole req");
return res.json();
}).then((resData) => {
console.log(resData);
console.log("req send successfully");
isLoading = false
// note = null;
}).catch((error) => {
// note = null;
console.log(error.message);
isLoading = false
// alert(error.message);
});
添加回答
举报