美文网首页
fetch vs xhr

fetch vs xhr

作者: monvhh | 来源:发表于2018-11-06 23:35 被阅读0次

    why fetch is so popular!!

    chrome的network都能看得出来是fetch还是xhr了。
    本来还以为fetch不就是xhr的一个包装么,就像jQuery的ajax一样……

    1. Promise vs callback

    2. 不支持同步请求 vs 支持同步请求

    3. 不支持同步请求 vs 支持取消请求

    4. 无法查看请求进度 vs xhr.onprogress回调查看请求进度

    5. fetch 提供Request和Response对象,同node.js!
      Response.body是一个ReadableStream。
      so,http status也是body的一部分。

    可以操纵response,返回假数据之类的,不过只能在ServiceWorker中。

    var myBody = new Blob();
    addEventListener('fetch', function(event) {
      event.respondWith(new Response(myBody, {
        headers: { "Content-Type" : "text/plain" }
      });
    });
    

    相关文章

      网友评论

          本文标题:fetch vs xhr

          本文链接:https://www.haomeiwen.com/subject/wewexqtx.html