实例化
ajax(config)
| 参数 | 示例 | 描述 |
|---|---|---|
| baseURL | location.origin | 请求的根域 |
| method | 'GET' | 请求方法:GET、POST、OPTIONS等 |
| url | '' | 请求地址,默认为请求的根域(未带http协议头) |
| data | null | 提交的参数数据 |
| headers | null | 修改提交时的请求头 |
| crossDomain | false | 是否跨域 |
| withCredentials | false | 是否携带凭证 |
| cache | true | 是否设置缓存 |
| responseType | 'json' | 响应数据类型 |
| timeout | 5000 | 请求超时时间 |
| jsonp | 'callback' | jsonp回调函数引用 |
| jsonpCallback | 'jsonp_XXXX' | jsonp回调函数名称 |
| dataFormatter | null | 数据格式化处理 |
| onTimeout | function(){} | 超时处理 |
创建实例
ajax.create(config)
通过实例可以设置基础规则,统一对系列接口进行请求
拦截器
instance.interceptors
设置请求拦截器
设置响应拦截器
通用请求
ajax.request(config)
GET请求
ajax.get(url,data,config)
POST请求
ajax.post(url,data,config)
PUSH请求
ajax.push(url,data,config)
PATCH请求
ajax.patch(url,data,config)
DELETE请求
ajax.delete(url,config)
HEAD请求
ajax.head(url,config)
OPTIONS请求
ajax.options(url,config)
JSONP请求
ajax.jsonp(url,data,config)
SSE连接
ajax.createEventSource(url,data,config)
