Gist - Fetch Usage
Introduction
Do you prefer the usage of "ES6 Promise"? If you do, you will like the usage of "Fetch" too.
Compared to "Ajax", "Fetch" owns a competitive feature: promise, which synchronize asynchronous methods elegantly, the meaning and the usage of "Fetch" can be understood easily as well.
Here, I'd like to list the most common usage of "Fetch".
Flow
The flow of fetching staff is simple:

Usage
Fetch once
Suppose we would fetch the content of an remote html
fetch('./data/test.html')
.then(function (response) {
return response.text() // return a promise
})
.then(function (body) {
console.log( body ) // log: html content
})
Fetch data right after the other data fetched(Chain)
If we'd like to fetch data(json) right after fetching content(html)
fetch('./data/test.html')
.then(response => {
return response.text()
})
.then(body => {
console.log(body)
return fetch('./data/test.json') // return a promise(`fetch('/url')` will return a promise )
})
.then(response => {
return response.json() // return a promise too
})
.then(json => {
console.log(json) // log: json's data
})
Complete all fetching action
Promise.all([
Promise.resolve(fetch('./data/test.html')),
Promise.resolve(fetch('./data/test.json'))
]).then(data => {
console.log('Two requests are both completed!')
})
API
Github Fetch Document
Offcial Manual
Conclusion
Fetch, well done!
Gist - Fetch Usage的更多相关文章
- [转]Backbone.js简单入门范例
本文转自:http://dmyz.org/archives/598 11年刚开始用前端MVC框架时写过一篇文章,当时Knockout和Backbone都在用,但之后的项目全是在用Backbone,主要 ...
- Backbone学习笔记一Backbone中的MVC
原文章地址http://bigdots.github.io/2015/12/01/Backbone学习笔记(一)/#more Backbone.js为复杂WEB应用程序提供模型(models).集合( ...
- nutch2.3命令参数解析
nutch中可执行的命令列表 [root@ewanalysis ~]# nutch Usage: nutch COMMAND where COMMAND is one of: inject injec ...
- Oracle Extended Tracing
Definitions A trace file is a file that contains diagnostic data used to investigate problems. Als ...
- 【比较基因组】McScan jcvi比较两个基因组共线性细节记录
目录 软件的安装 基因组的准备 一些细节 建议和示例 软件的安装 Python版McScan(jcvi工具包):https://github.com/tanghaibao/jcvi 以前只有pytho ...
- .Net EF Core数据库使用SQL server 2008 R2分页报错How to avoid the “Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement.”
一. 问题说明 最近.Net EF core 程序部署到服务器,服务器数据库安装的是SQL server 2008 R2,我本地用的的是SQL server 2014,在用到分页查询时报错如下: H ...
- .NET Core EF框架使用SQL server 2008数据库分页问题:Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement
一. 问题 最近.Net Core程序部署到服务器,采用EF6.本地数据库是SQL server 2016,服务器数据库安装的是SQL server 2008 R2,在用到分页查询时报错如下: { & ...
- usage: git remote add [<options>] <name> <url> -f, --fetch fetch the remote branches --tags import all tags and associated objects when fetching
按照git官网提示输入 git pushgit remote add origin git@github.com:***3 / elm-1.git -u 链接git远程仓库 出现错误 usage: g ...
- 升级 nop 4.1 Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement.
Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement. nop.web 项目 ...
随机推荐
- 使用SpringBoot快速构建应用程序
1.Spring MVC和Spring Boot自带的web构建方式有所区别.Spring提供了spring-boot-starter-web自动配置模块. 2. 添加如下依赖 <depende ...
- java关键字transient与volatile小结
本文转自:http://heaven-arch.iteye.com/blog/1160693 transient和volatile两个关键字一个用于对象序列化,一个用于线程同步,都是Java中比较高阶 ...
- java面向对象--包及访问控制符
多人开发同一个项目时,会出现类名称相同的情况.package就是为了避免类或接口名称重复而采用的一种措施.实际上包就是有一定层次结构的文件夹,*.class文件要保存当前类声明的和包对应的文件夹中. ...
- 第 4 章 MySQL 安全管理
前言 对于任何一个企业来说,其数据库系统中所保存数据的安全性无疑是非常重要的,尤其是公司的有些商业数据,可能数据就是公司的根本,失去了数据的安全性,可能就是失去了公司的一切.本章将针对 MySQL 的 ...
- [原创]MongoDB综合实例一
CentOS-6.5单机实现mongoDB分片 环境:1)CentOS 6.5系统 2)IP:本机3)MongoDB:MongoDB-linux-x86_64-2.6.1 实现:两个副本集s ...
- angular实现的文字上下无缝滚动
最近在学习angularJs,业余时间随便写了一个文字上下无缝滚动的例子,主要写了一个小小的指令. css代码:主要控制样式 <style type="text/css"&g ...
- 刨根究底字符编码之十一——UTF-8编码方式与字节序标记
UTF-8编码方式与字节序标记 一.UTF-8编码方式 1. 接下来将分别介绍Unicode字符集的三种编码方式:UTF-8.UTF-16.UTF-32.这里先介绍应用最为广泛的UTF-8. 为满足基 ...
- 【小练习06】HTML+CSS--电影公告
要求实现如下效果图: 代码演示 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- Python给多个变量赋值
# Assign values directly a, b = 0, 1 assert a == 0 assert b == 1 # Assign values from a list (r,g,b) ...
- WPF界面XAML中的if……else……
xaml本身并不支持if--else--,要用Converter替代if--else--来实现我们想要的效果,知者请速离开,不要浪费时间 需求:按照Window的WindowState来决定Gri ...