npm.io
0.2.0 • Published 8 years ago

ajax-camp

Licence
MIT
Version
0.2.0
Deps
1
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

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
})

Keywords