then-ajax
v0.2.0
Published
async ajax base on $.ajax
Downloads
29
Readme
then-ajax
安装
npm install then-ajax --save
使用
import {thenAjax, thenPost, thenGet, thenJsonp, IAjaxOptions} from 'then-ajax'
api
thenAjax(opts): Promise
opts.url
(string) 请求 URLopts.data
(object) 数据 data, optionalopts.methods
(string) 请求类型 默认值get
, optionalopts.contentType
(string) header content-type, optionalopts.async
(boolean) async, optionalopts.timeout
(number) 设置超时时间, optionalopts.before
(function) 请求前执行函数, optionalopts.jsonp
(string) 设置 jsonp 默认值为callback
, optionalopts.jsonpcb
(string) 设置 jsonpcb 名称, optional
thenGet(url, data, opts): Promise
url
(string) 请求 URLdata
(object) 数据 data, optionalopts
(object) 同上,略, optional
thenPost(url, data, opts): Promise
url
(string) 请求 URLdata
(object) 数据 data, optionalopts
(object) 同上,略, optional
thenJsonp(url, data, opts): Promise
url
(string) 请求 URLdata
(object) 数据 data, optionalopts
(object) 同上,略, optional
example
import syncJsonp from 'sync-jsonp';
thenAjax({
dataType: 'json',
url: 'http://hostname.com/path/to/api'
}).then((data) => {
console.log('===', data);
});
thenAjax({
data: {
a: 2
},
dataType: 'json',
url: 'http://hostname.com/path/to/api',
}).then((data) => {
console.log('===', data);
});