Fetch 是 window.fEtchJavaScript polyfill。

全局 fetch 函数是 web 请求和处理响应的简单方式,不使用 XMLHTTPRequest。这个 polyfill 编写的接近标准的 Fetch 规范(https://fetch.spec.whatwg.org)。

fetch 函数支持所有的 HTTP 方式:

HTML:

fetch('/users.html')
  .then(Function(response) {
    return response.text()
  }).then(function(body) {
    document.body.innerHTML = body
  })

JSON

fetch('/users.json')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })
深入浅出Fetch API
本篇内容主要为大家提供的是深入浅出Fetch API。感兴趣的同学可以参考学习下,具体内容如下:

发布于 2016-01-21 13:50:43 | 1007 次阅读


Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务