栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Rxjs 5

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Rxjs 5

Observable.ajax
可以接受
string
Object
具有以下界面:

interface AjaxRequest {  url?: string; // URL of the request  body?: any;  // The body of the request  user?: string;  async?: boolean; // Whether the request is async  method?: string; // Method of the request, such as GET, POST, PUT,

PATCH, DELETE
headers?: Object; // Optional headers
timeout?: number;
password?: string;
hasContent?: boolean;
crossDomain?: boolean; //true if a cross domain request, else false
withCredentials?: boolean;
createXHR?: () => XMLHttpRequest; //a function to override if you need
to use an alternate XMLHttpRequest implementation
progressSubscriber?: Subscriber;
responseType?: string;
}


在GitHub上查看AjaxObservable.ts

这是示例:

const { Observable, combineLatest } = rxjs; // = require("rxjs")const { ajax } = rxjs.ajax; // = require("rxjs/ajax")const { map } = rxjs.operators; // = require("rxjs/operators")// simple GET request exampleconst simple$ = ajax('https://httpbin.org/get');// POST request exampleconst complex$ = ajax({  url: 'https://httpbin.org/post',  method: 'POST',  headers: {    'Content-Type': 'application/json',    'x-rxjs-is': 'Awesome!'  },  body: {    hello: 'World!',  }});const htmlSubscription = combineLatest(simple$, complex$)  .subscribe(([simple, complex]) => {    const simpleResponse = JSON.stringify(simple.response, null, 2);    const complexResponse = JSON.stringify(complex.response, null, 2);    document.getElementById('root').innerHTML = `      <div>        <span><b>GET</b> https://httpbin.org/get</span>        <pre>${simpleResponse}</pre>        <span><b>POST</b> https://httpbin.org/post</span>        <pre>${complexResponse}</pre>      </div>`;  });<script src="https://unpkg.com/rxjs@6.2.2/bundles/rxjs.umd.min.js"></script><div id="root">loading ...</div>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/381708.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号