无法使用HTTP Post方法发送id



我想在使用HTTP Post方法单击按钮时发送按钮的id,我编写了以下代码。但是当我按下按钮时,服务器没有接收到按钮的id。谁能告诉我,这里出了什么问题?提前感谢。

<HTML>
<head>
<script>
function fun1(element) {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/prc", true);
xhttp.send(element.id);
//alert("ID":element.id);
}
</script>
</head>
<body>
<button type="button" onclick="fun1(this)" id="img1">IMAGE</button>
</body>
</html>

我建议你使用Fetch API,因为它有更简单的接口:

function fun1(element) {
fetch('/prc', { method: 'POST', body: element.id })
}

最新更新