fetch API 和 ajax

 

fetch('/some.json', {
    method: 'get',
    body: { id: 22 }
}).then(function (resp) {
    resp.json().then(console.log);

}).catch(function (r) {
    console.err(r);
});

 

 

$.ajax({
    url: '/xxx',  // 代表请求的服务器地址
    method: 'get|post|put|patch|delete|options', // 使用的请求方法
    headers: {},  // 设置请求头
    async: true|false, // 是否使用异步请求的方式

    contentType: 'application/x-www-form-urlencoded|...', // 请求的 enctype
    data: 'String'|Object|Array, // 传输的数据
    processData: true|false, // 如果 data 是字符串的话不处理,否则调用 $.params(data, tranditional) => 'aaa=222&bbb=333'
    tranditional: false|true,

    dataType: 'json?xml?html?text', // 默认根据 response 头部的信息自动推测
    xhrFields, cache, accepts, contents, crossDomain, conerters, jsonp, mimeType, timeout
}).done((data) => {  // data 的类型,由 dataType 决定
    console.log(json.xxx)
}).fail((xhr, status, err) { // 参数分别是 ajax 原生对象,错误状态,以及错误对象
    console.error(err);
}).always(() => {
    console.log("终于结束了");
});

 

转载于:https://www.cnblogs.com/ldl326308/p/10386866.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值