加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

fetch API 和 ajax

发布时间:2020-12-16 02:58:16 所属栏目:百科 来源:网络整理
导读:? 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|pa

?

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("终于结束了");
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读