Home >Web Front-end >JS Tutorial >JS uses the POST request method in json format

JS uses the POST request method in json format

小云云
小云云Original
2018-03-30 09:36:243133browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn