axios 发送 AJAX请求
生活随笔
收集整理的这篇文章主要介绍了
axios 发送 AJAX请求
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>axios 发送 AJAX请求</title><script crossorigin="anonymous" src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
</head><body><button>GET</button><button>POST</button><button>AJAX</button><script>// https://github.com/axios/axiosconst btns = document.querySelectorAll('button');//配置 baseURLaxios.defaults.baseURL = 'http://127.0.0.1:8000';btns[0].onclick = function () {//GET 请求axios.get('/axios-server', {//url 参数params: {id: 100,vip: 7},//请求头信息headers: {name: 'atguigu',age: 20}}).then(value => {console.log(value);});}btns[1].onclick = function () {axios.post('/axios-server', { //第二个参数是请求体username: 'admin',password: 'admin'}, { // 第三个参数 其他配置// 请求参数params: {id: 200,vip: 9},//请求头参数headers: {height: 180,weight: 180,}});}btns[2].onclick = function(){axios({//请求方法method : 'POST',//urlurl: '/axios-server',//url参数params: {vip:10,level:30},//头信息headers: {a:100,b:200},//请求体参数data: {username: 'admin',password: 'admin'}}).then(response=>{//响应状态码console.log(response.status);//响应状态字符串console.log(response.statusText);//响应头信息console.log(response.headers);//响应体console.log(response.data);})}</script>
</body></html>
总结
以上是生活随笔为你收集整理的axios 发送 AJAX请求的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: fetch 发送 AJAX请求
- 下一篇: jQuery 发送 AJAX 请求