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 请求