1.0.4 • Published 8 years ago
dn-fetch-polyfill v1.0.4
window.fetch polyfill
Installation
$ npm install dbl-fetch-polyfill --saveRun this to polyfill the global environment at the beginning of your application.
import fetch from dbl-fetch-polyfill(For a node.js implementation, try node-fetch)
Usage
The fetch function supports any HTTP method. We'll focus on GET and POST
example requests.
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)
  })Response metadata
fetch('/users.json').then(function(response) {
  console.log(response.headers.get('Content-Type'))
  console.log(response.headers.get('Date'))
  console.log(response.status)
  console.log(response.statusText)
})Post form
log
- 1.0.4 跟facked冲突
 
1.0.4
8 years ago