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

JS uses the POST request method in json format

小云云
Release: 2018-03-30 09:36:24
Original
3103 people have browsed it

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">
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template