Created
December 17, 2021 05:09
-
-
Save itherunder/756c09eda72881c97b78ef0786aa2af7 to your computer and use it in GitHub Desktop.
在浏览器的控制台里面发送请求
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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