0.2.0 • Published 6 years ago
ajax-camp v0.2.0
ajax-camp
A ajax library of javascript.
API Reference
ajax
参数 | 描述 | 类型 | 值域 | 默认值 | 是否必须 | |
---|---|---|---|---|---|---|
url | 请求地址 | String | 无 | 无 | 是 | |
method | 请求类型 | String | get, post, jsonp | get | 否 | |
timeout | 请求超时时间,默认不会超时 | Number | 无 | 0 | 否 | |
credentials | 跨域请求是否可以发送凭据(例如:Cookie) | Boolean | 无 | false | 否 | |
headers | 请求头部 | Object | 无 | {'Accept': '/', 'Content-Type': 'application/x-www-form-urlencoded'} | 否 | |
params | get请求参数 | Object | 无 | {} | 否 | |
body | post请求参数,支持FormData | Object | 无 | null | 否 | |
progress | 请求实时进度 | Function | 无 | 无 | null | 否 |
Response
参数 | 描述 | 类型 |
---|---|---|
status | 状态码 | Number |
statusText | 状态描述 | String |
result | 返回数据 | Any |
AjaxCamp (api)
example
const api = {
getRepoIssues: {
url: '/issues',
method: 'jsonp',
params: {
sort: {
type: String,
default: 'updated' // created, updated, comments
},
page: {
type: [Number, String],
required: true
},
per_page: {
type: [Number, String],
default: 10
}
}
}
}
const camp = new AjaxCamp(api)
// usage
camp.getApi('getRepoIssues', {
sort: 'updated',
page: 1,
per_page: 10
}).then(res => {
// do something
})