This article mainly shares with you the JS method of sending POST requests in json format. It is mainly shared with you in the form of code. I hope it can help you.
<script type="text/javascript">
Use JS to send a POST request in JSON format
var us = new US(); var xhr = new XMLHttpRequest(); xhr.open("POST", "/searchguard/api/v1/auth/login", true); xhr.setRequestHeader("Content-type", "application/json"); xhr.setRequestHeader("kbn-version", "5.3.0"); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { window.location.href = us.nextUrl; } } }; xhr.send(JSON.stringify({ "username" : us.u, "password" : us.p })); </script>
Related recommendations:
php curl get post request usage Example sharing
The above is the detailed content of JS uses the POST request method in json format. For more information, please follow other related articles on the PHP Chinese website!