分js、ajax方式发送http请求。
js
在js方法内1
2
3
4
5
6
7
8
9
10
11
12
13function xxxx() {
let xhr = new XMLHttpRequest();
xhr.open("POST", "/admin/qrcode_add");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
}};
xhr.send(JSON.stringify(post_params));
}ajax
1
2
3
4
5
6
7
8
9
10
11//填写后台给的参数
var post_params = {"recipient_email": email, "username": username};
$.ajax({
type: 'post',
url: '/send_mail',
data: JSON.stringify(post_params),
contentType: 'application/json',
success: function(res){
console.log(res);
}
});
