js fetch api
MDN
fatch
返回的对象
type string
url string
redirected boolean
status number
ok boolean
statusText string
headers object
body object
bodyUsed boolean
clone function
arrayBuffer function
blob function
formData function
json function
text function
get 和 post
get() {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let option = {
method: 'GET',
headers: headers,
mode: 'cors',
cache: 'default'
};
let request = new Request('/get', option);
fetch(request).then(res => res.json()).then(res => console.log(res));
post() {
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
let option = {
method: 'POST',
headers: headers,
mode: 'cors',
cache: 'default'
};
let request = new Request('/post', option);
fetch(request).then(res => res.json()).then(res => console.log(res));
}
rxjs的ajax
rxjs.ajax.ajax.get('/get',{'content-type': 'application/json'})
.pipe(
rxjs.operators.map(res => res.response)
)
.subscribe(
v => { console.log(v) },
e => { console.log(e) },
() => { console.log('complete') }
);
rxjs.ajax.ajax.post('/post',{'content-type': 'application/x-www-form-urlencoded;charset=utf-8'})
.pipe(
rxjs.operators.map(res => res.response)
)
.subscribe(
v => { console.log(v) },
e => { console.log(e) },
() => { console.log('complete') }
);
rxjs 包装 fetch
let get$ = rxjs.from(fetch('/get', {
method: 'GET',
headers: headers
}))
get$.pipe( rxjs.operators.mergeMap(res => rxjs.from(res.json())))
.subscribe(res => console.log( res))
并发请求
let get$ = rxjs.from(fetch('/get', {
method: 'GET',
headers: headers
}))
let get1$ = rxjs.from(fetch('/get1', {
method: 'GET',
headers: headers
}))
let get2$ = rxjs.from(fetch('/get2', {
method: 'GET',
headers: headers
}))
rxjs.merge(get$, get1$, get2$)
.pipe(
rxjs.operators.mergeMap(res => rxjs.from(res.json()))
)
.subscribe(res => console.log(res), err => console.error(err))
js fetch api的更多相关文章
- (转)这个API很“迷人”——新的Fetch API
原文:https://hacks.mozilla.org/2015/03/this-api-is-so-fetching 原标题是This API is So Fetching,Fetching也可以 ...
- Fetch API & Delete & HTTP Methods
Fetch API & Delete & HTTP Methods vue https://developer.mozilla.org/en-US/docs/Web/API/Fetch ...
- 基于Promise规范的fetch API的使用
基于Promise规范的fetch API的使用 fetch的使用 作用:fetch 这个API,是专门用来发起Ajax请求的: fetch 是由原生 JS 提供的 API ,专门用来取代 XHR 这 ...
- Axios & fetch api & Promise & POST
Axios & fetch api & Promise & POST https://github.com/axios/axios https://appdividend.co ...
- fetch API 简单解读
http://f2e.souche.com/blog/fetch-api-jie-du/?utm_source=tuicool&utm_medium=referral 在我们日常的前端开发中, ...
- ES6 Fetch API HTTP请求实用指南
本次将介绍如何使用Fetch API(ES6 +)对REST API的 HTTP请求,还有一些示例提供给大家便于大家理解. 注意:所有示例均在带有箭头功能的 ES6中给出. 当前的Web /移动应用程 ...
- Fetch API与POST请求那些事
简述 相信不少前端开发童鞋与后端联调接口时,都会碰到前端明明已经传了参数,后端童鞋却说没有收到,尤其是post请求,遇到的非常多.本文以node.js作为服务端语言,借用express框架,简要分析客 ...
- js Fetch返回数据res.json()报错问题
前言 一直以来在简单的场景中经常使用fetch代替第三方请求库, fetch是JavaScript的原生函数, 简单.高效.快速.稳定.可定制等等诸多优点.一直也是用着很是舒服,直到有一天它竟然报错了 ...
- 原生JS实战:写了个一边玩游戏,一边记JS的API的游戏
本文是苏福的原创文章,转载请注明出处:苏福CNblog:http://www.cnblogs.com/susufufu/p/5878913.html 本程序[一边玩游戏,一边记JS的API]是本人的个 ...
随机推荐
- 在 Visual Studio 2010 中配置SharpPcap
最近需要在C#下写一个抓取ARP包的程序,网上找来找去,在C#下只能用SharpPcap来做了.SharpPcap是作者把winPcap用C#重新封装而来的,详细信息见如下的链接. SharpPcap ...
- python的匿名函数lambda解释及用法
lambda函数的语法只包含一个语句,如下: lambda arg1,arg2,.....argn:expression(主要是看下面的例子)代码示例: #-*- coding:utf-8 -* ...
- scala recursive value x$5 needs type
recursive value x$5 needs type的原因是使用了一个类型不确定的变量,例如 val (id, name) = (id, getName(id)) 其中id是个变量,其值还不确 ...
- 【翻译自mos文章】在10g中,当发生ORA-00020时,sqlplus登陆会报“connected to an idle instance”
在10g中.当发生ORA-00020时,sqlplus登陆会报"connected to an idle instance" 来源于: Sqlplus Logon Reports ...
- LINQ to Entities 比较日期
//获取当天的数据 DrawRecordDA _recordDA = new DrawRecordDA(); var query = _recordDA.GetQuery(); //筛选 当天 //q ...
- Rocket Typist for Mac(增强型文本快速输入工具)破解版安装
1.软件简介 Rocket Typist 是 macOS 系统上一款增强型文本快速输入工具,我们可以利用这款工具预先设置保存好很多日常生活学习或是工作中常用的文本片段,还能设定部分内容为变量,当 ...
- linux删除软连接
#mkdir test_chk #touch test_chk/test.txt #vim test_chk/test.txt (这一步随便在这个test.txt里写点东东即可) 下面我们来创建tes ...
- Linux install svn server
ref: http://blog.csdn.net/pingnanlee/article/details/8812520 1. yum -y install subversion 2. svnadmi ...
- Fluent动网格【2】:Profile文件
动网格中一个重要任务是部件运动方式的指定.在动网格中指定部件的运动,往往将部件的运动方式指定为其加速度.速度或位移与时间的相关关系,本文主要讲述如何在Fluent中利用瞬态Profile文件指定部件的 ...
- 【ZooKeeper】ZooKeeper入门流水记
单机模式 下载zookeeper的包 wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.ta ...