Jquery请求对象有一个名为'data'的属性,用于设置表单数据并使用正确的标题发出表单请求。
我想在rxjs ajax中实现相同但无法找到方法。 我能找到的唯一详尽的请求配置属性列表是https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/doc/operators/ajax.md
答案 0 :(得分:2)
RxJS5的文档尚未完成,但您可以按如下方式使用它:
import {Observable} from "rxjs/Observable";
import "rxjs/add/observable/dom/ajax";
const url = "http://my-site.org/some/endpoint";
const request$ = Observable.ajax.put(url, {a: "test"});
request$.subscribe(x => console.log(x));
当然所有其他REST方法都可用
Observable.ajax(urlOrRequest: string | AjaxRequest): Observable<AjaxResponse>;
Observable.ajax.get(url: string, headers?: Object): Observable<AjaxResponse>;
Observable.ajax.post(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
Observable.ajax.put(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
Observable.ajax.patch(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
Observable.ajax.delete(url: string, headers?: Object): Observable<AjaxResponse>;
Observable.ajax.getJSON<T>(url: string, headers?: Object): Observable<T>;
如果要发送完全自定义的ajax请求,可以使用以下界面:
interface AjaxRequest {
url?: string;
body?: any;
user?: string;
async?: boolean;
method?: string;
headers?: Object;
timeout?: number;
password?: string;
hasContent?: boolean;
crossDomain?: boolean;
withCredentials?: boolean;
createXHR?: () => XMLHttpRequest;
progressSubscriber?: Subscriber<any>;
responseType?: string;
}