0
点赞
收藏
分享

微信扫一扫

axios和ajax的区别是什么

何以至千里 2022-09-15 阅读 154

一、axios 和 ajax 的区别

二、axios 和 ajax 的区别及优缺点

ajax:

1、什么是ajax

2、ajax的原理?

3、核心对象?

4、ajax优缺点?

   优点 

   缺点:

5、Ajax适用场景

6、Ajax不适用场景

7、代码

$.ajax({
   type: 'get',
   url: '/getuser/data',
   dataType: 'json',
   data: {
        firstName: '张',
        lastName: '三'
   },
   success: function (response) {
       console.log(response);
   },
   error: function (error) {
	   console.log(error);
   }
});

8、ajax请求的五个步骤

axios:

1、axios是什么

2、axios有那些特性?

3、执行get请求,有两种方式

// 第一种方式  将参数直接写在url中
axios.get('/getMainInfo?id=123').then((res) => {
  console.log(res)
}).catch((err) => {
  console.log(err)
})

// 第二种方式  将参数直接写在params中
axios.get('/getMainInfo', {  
  params: {
    id: 123
  }
}).then((res) => {
  console.log(res)
}).catch((err) => {
  console.log(err)
})

4、执行post请求,注意执行post请求的入参,不需要写在params字段中,这个地方要注意与get请求的第二种方式进行区别。

axios.post('/getMainInfo', {
  id: 123
}).then((res) => {
  console.log(res)
}).catch((err) => {
  console.log(err)
})

5、执行代码 

 axios({
        url: '/getUsers',
        method: 'get',
        responseType: 'json', // 默认的
        data: {
            //'a': 1,
            //'b': 2,
        }
    }).then(function (response) {
        console.log(response);
        console.log(response.data);
    }).catch(function (error) {
        console.log(error);
    });

三、axios和ajax的区别

举报

相关推荐

0 条评论