axios CDN introduction link
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
axios GET request
const btns = document.querySelectorAll('button');
axios.defaults.baseURL = 'http://localhost:8000';
btns[0].onclick = function() {
axios.get('/axios-server',{
params: {
id: 666666,
name: 'justin'
},
headers: {
color: "red"
}
}).then(value => {
console.log(value);})
}
axios POST request
btns[1].onclick = function () {
axios.post('/axios-server',{
username: 'pink',
password: 123456
}, {
params: {
id: 999,
school: 'Tsinghua'
},
headers: {
height: 600,
weight: 300
}
})
}
- The first parameter is the URL
- The second parameter is the request body
- The third parameter is the request header parameter
Axios general function to send request
btns[2].onclick = function() {
axios({
method: 'POST',
url: '/axios-server',
params: {
vip: 100,
name: 'jusitn'
},
headers: {
a: 100,
b: 30000
},
data: {
username: 'admin',
password: 123456
}
}).then(value => {
console.log(value);})
}