Skip to content

Instantly share code, notes, and snippets.

@itherunder
Created December 17, 2021 05:09
Show Gist options
  • Save itherunder/756c09eda72881c97b78ef0786aa2af7 to your computer and use it in GitHub Desktop.
Save itherunder/756c09eda72881c97b78ef0786aa2af7 to your computer and use it in GitHub Desktop.
在浏览器的控制台里面发送请求
//POST
function post(url, params) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(JSON.stringify(params));
}
var url = "/buyout/order/queryOrderList";
var params = {advertiserUid: 1232131, advertiserWeiboNickname: "18"};
post(url, params);
//GET
function get(url) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
}
var url = "/buyout/order/queryOrderList?types=userType,userStatus";
get(url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment