在传递参数时,需要确保参数为正数。也可以通过将参数转换为字符串的方法避免该问题,例如:
const data = {
amount: Math.abs(-10),
// 其他参数
}
fetch('/api/endpoint', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {
// 处理响应
})
.catch(error => {
// 处理错误
});