js fetch api
2024-10-15 15:58:26
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))
最新文章
- python 培训之Django
- App lifecycle(UWP深入学习一)
- 关于一个js连续赋值问题之我见(词略穷,见谅)
- html 构建响应式网站之viewport的使用
- 移动端 :meta标签1万个作用
- 在jsp页面解析json的2种方法
- 两个栈实现一个队列,C语言实现,队列可伸缩,容纳任意数目的元素。
- 如何在不影响数据库的正常使用的情况下得到数据的完整.mdf和.ldf文
- iPhone之为UIView设置阴影(CALayer的shadowColor,shadowOffset,shadowOpacity,shadowRadius,shadowPath属性)
- 【转】独立游戏如何对接STEAM SDK
- restTemplate.postForObject上传文件中文乱码(???.xls)
- [QTree6]Query on a tree VI
- SkylineGlobe 移动端开发测试
- CoordTools
- opencv矩阵操作
- JVM JRE JDK三者的区别和联系
- 6.JXL操作Excel
- [leetcode]Reorder List @ Python
- 关于LoadRunner的迭代
- 微信公众号支付安卓和WP支付成功,苹果不能支付!