版权声明:欢迎copy,只求有用 https://blog.csdn.net/muzhe1024/article/details/83617891
格式略 写不进去
!!!
<script src="js/axios.min.js"></script>
<script>
window.onload = function(){
// 1.第一种
axios({
// a.路径
url: '/index_data',
// b.提交类型
method: 'get/post',
// c.传递参数
'data/params': {
username: '张三',
password: '123456',
},
// d.返回数据类型
// responseType: 'text/json...',
})
.then(function(obj){
console.log(obj.data)
})
.catch(function(){
alert('服务器异常...')
})
// 2.第二种。
axios.get('/index_data?username="aaa"&password="bbb"')
.then(function(obj){
console.log(obj.data)
})
.catch(function(){
alert('服务器异常...')
})
// 3.第三种。
axios.get('/index_data', {
params: {
username: 'aaa',
password: 'bbb',
},
})
.then(function(obj){
console.log(obj.data)
})
.catch(function(){
alert('服务器异常...')
})
// 4.第四种。
axios.post('/index_data', {
username: 'aaa',
password: 'bbb',
})
.then(function(obj){
console.log(obj.data)
})
.catch(function(){
alert('服务器异常...')
})
}
</script>