-1

I want to send the id of a button when it is clicked using HTTP Post method, I've written the following code. But the server is not receiving the id of the button when I press the button. could anyone please guide me, what's going wrong here? Thanks in Advance.

<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>
Shubham
  • 17
  • 1
  • 3

1 Answers1

-1

I suggest you using Fetch API as it has much simpler interface:

function fun1(element) {
  fetch('/prc', { method: 'POST', body: element.id })
}
BANO notIT
  • 360
  • 1
  • 12