I have looked many places and even here on stack overflow, but I cannot find information on sending JSON data in HTML / JS in a PUT request. I have tried many things, but I have not yet found a way.
I have went online and found that you can use stringify() and XMLHttpRequest, I have tried the following with no success.
<script>
var xmlhttp = new XMLHttpRequest();
var theUrl = "/";
xmlhttp.open("PUT", theUrl);
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send(JSON.stringify({ "test": "my data"}));
</script>
I currently am having to create a website, but I am currently required to send a PUT request to another website containing JSON data. Down below is a very simple representation of what I am trying to do.
<html>
<body>
<form action="https://www.theOtherWebsite.com" method="PUT">
<!-- JSON data to send upon pressing submit -->
<button type="submit" name="button">submit</button>
</form>
</body>
</html>
If anyone has information on a solution that would be great.
If I have to use a server, I could, but I would still need to somehow send this request to a third party website with the JSON data which I have not been able to find out how to do either.