1.get无参数// 1.创建实例对象
var xhr=new XMLHttpRequest();
// 2.打开一个连接
xhr.open("get",'http://47.93.206.13:8002/index/findAllCategory');
// 3.发送请求
xhr.send();
// 4.接收响应
xhr.onreadystatechange=function(){
if(xhr.readyState===4&xhr.status===200){
console.log(xhr.responseText)
}
}
```
```javascript
2.get携带参数 var qs=Qs
// 创建一个实例
var xhr=new XMLHttpRequest();
// 2.打开一个连接
let obj={
page:1,
pageSize:10
}
console.log(qs.stringify(obj))
xhr.open('get',"http://47.93.206.13:8002/index/pageQueryArticles"+'?'+qs.stringify(obj));
xhr.send();
// 4.接收响应
xhr.onreadystatechange=function(){
if(xhr.readyState===4&xhr.status===200){
console.log(xhr.responseText)
}
}
```
```javascript
3. post携带参数 // 创建一个实例
var xhr=new XMLHttpRequest();
// 2.打开一个连接
let obj={
username:'admin1',
password:123321
}
xhr.open('post',"http://47.93.206.13:8002/user/login");
xhr.setRequestHeader('Content-Type','application/json')
xhr.send(
JSON.stringify(obj)
);
// 4.接收响应
xhr.onreadystatechange=function(){
if(xhr.readyState===4&xhr.status===200){
console.log(xhr.responseText)
}
}
```