微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

封装自己的Ajax函数

itheima()函数是我们自定义的Ajax函数、它接收一个配置对象作为参数、配置对象中可以配置如下属性:

method   请求的类型

url   请求的URL地址

data   请求携带的数据

success   请求成功之后的回调函数

 

发送GET

itheima({
    method: 'GET',
    url: 'http://www.liulongbin.top:3006/api/getbooks',
    data: {
      id: 1
    },
    success: function (res) {
      console.log(res);
    }
  })

 

发送POST

itheima({
    method: 'post',
    url: 'http://www.liulongbin.top:3006/api/addbook',
    data: {
      bookname: '水浒传',
      author: '施耐庵',
      publisher: '北京图书出版社'
    },
    success: function (res) {
      console.log(res);
    }
  })

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐