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的更多相关文章

  1. (转)这个API很“迷人”——新的Fetch API

    原文:https://hacks.mozilla.org/2015/03/this-api-is-so-fetching 原标题是This API is So Fetching,Fetching也可以 ...

  2. Fetch API & Delete & HTTP Methods

    Fetch API & Delete & HTTP Methods vue https://developer.mozilla.org/en-US/docs/Web/API/Fetch ...

  3. 基于Promise规范的fetch API的使用

    基于Promise规范的fetch API的使用 fetch的使用 作用:fetch 这个API,是专门用来发起Ajax请求的: fetch 是由原生 JS 提供的 API ,专门用来取代 XHR 这 ...

  4. Axios & fetch api & Promise & POST

    Axios & fetch api & Promise & POST https://github.com/axios/axios https://appdividend.co ...

  5. fetch API 简单解读

    http://f2e.souche.com/blog/fetch-api-jie-du/?utm_source=tuicool&utm_medium=referral 在我们日常的前端开发中, ...

  6. ES6 Fetch API HTTP请求实用指南

    本次将介绍如何使用Fetch API(ES6 +)对REST API的 HTTP请求,还有一些示例提供给大家便于大家理解. 注意:所有示例均在带有箭头功能的 ES6中给出. 当前的Web /移动应用程 ...

  7. Fetch API与POST请求那些事

    简述 相信不少前端开发童鞋与后端联调接口时,都会碰到前端明明已经传了参数,后端童鞋却说没有收到,尤其是post请求,遇到的非常多.本文以node.js作为服务端语言,借用express框架,简要分析客 ...

  8. js Fetch返回数据res.json()报错问题

    前言 一直以来在简单的场景中经常使用fetch代替第三方请求库, fetch是JavaScript的原生函数, 简单.高效.快速.稳定.可定制等等诸多优点.一直也是用着很是舒服,直到有一天它竟然报错了 ...

  9. 原生JS实战:写了个一边玩游戏,一边记JS的API的游戏

    本文是苏福的原创文章,转载请注明出处:苏福CNblog:http://www.cnblogs.com/susufufu/p/5878913.html 本程序[一边玩游戏,一边记JS的API]是本人的个 ...

随机推荐

  1. [leetcode]Largest Rectangle in Histogram @ Python

    原题地址:https://oj.leetcode.com/problems/largest-rectangle-in-histogram/ 题意: Given n non-negative integ ...

  2. yolov3源码darknet在vscode下调试

    1. 安装配置: https://pjreddie.com/darknet/yolo/ darknet文件夹下make命令搞定: 2. 配置vscode 打开安装好的vscode并安装扩展C/C++( ...

  3. Android 实战之酷云(一)

    前言 大家好啊!好久没有见到我了吧.为什么呢!当然是由于开学啦,这学期非常多课,身为部长实验室也也非常多活动和一堆小师弟.同一时候还有蓝桥杯和华为软件开发大赛.并且近期在做一个综合性比較高的作品,没错 ...

  4. MDX Step by Step 读书笔记(七) - Performing Aggregation 聚合函数之 Max, Min, Count , DistinctCount 以及其它 TopCount, Generate

    MDX 中最大值和最小值 MDX 中最大值和最小值函数的语法和之前看到的 Sum 以及 Aggregate 等聚合函数基本上是一样的: Max( {Set} [, Expression]) Min( ...

  5. VTK计算网格模型上的最短路径

    Dijkstra algorithm to compute the graph geodesic.Takes as input a polygonal mesh and performs a sing ...

  6. IDEA环境设置

    设置SDK:https://blog.csdn.net/y999666/article/details/51893348 打开模板使用说明,找到Maven本地安装目录, 备份E:\Program Fi ...

  7. Xilinx 常用模块汇总(verilog)【02】

    作者:桂. 时间:2018-05-08  18:35:56 链接:http://www.cnblogs.com/xingshansi/p/9010282.html [本文遗留几处细节问题,待闲下来解决 ...

  8. C# 给枚举类型增加一个备注特性

    /// <summary> /// 备注特性 /// </summary> public class RemarkAttribute : Attribute { /// < ...

  9. mac无法访问samba共享 提示输入用户名密码

    这时候需要输入mac笔记本的用户名和密码 也可以在samba服务器上增加用用户: # smbpasswd -a user_nameNew SMB password:Retype new SMB pas ...

  10. pandas DataFrame applymap()函数

    pandas DataFrame的 applymap() 函数可以对DataFrame里的每个值进行处理,然后返回一个新的DataFrame: import pandas as pd df = pd. ...