AJAX vjspUtils.ajax
对于ajax相关封装
Members
(static,readonly).defaultOptions:Object
属性
Name | Type | Default | Description |
---|---|---|---|
url | String | 请求的URL | |
async | Boolean | true | 同步(false)/异步(true) 请求 |
type | String | post | 请求方式(get|post) |
cache | Boolean | false | 在 GET 请求方式下,是否缓存 |
contentType | String | application/x-www -form-urlencoded | 发送信息至服务器时内容编码类型,默认值适 合大多数情况 |
success | function | 请求成功的回调函数 | |
error | function | 请求失败的回调函数 | |
data | Object | {} | 发送到服务器的数据 |
charset | String | null | 内容编码,非jQuery ajax 参数 |
jQuery ajax 常用设置的默认值
Type: Object
(static, readonly).jsonpDefaultOptions:Object
属性
Name | Type | Default | Description |
---|---|---|---|
type | String | get | jsonp只能是get方式 |
dataType | String | jsonp | 设置为 jsonp 表示跨域ajax请求 |
jsonp | String | callback | 向后台提供回调函数名的参数 |
jsonpCallback | String | 回调函数名 |
跨域ajax 默认设置
Type: Object
Methods
(static).vjspAjax(options) →{Object}
See: vjspUtils.ajax.defaultOptions
对于jQuery ajax简单封装
主要是对于默认参数的整合和自定义参数(如charset)逻辑的添加
示例:
//console output {name: "test json", used: "test ajax function"}
vjspUtils.ajax.vjspAjax({
url:'testjson/data1.json',
type:'get',
success:function(d){
console.info(d);
}
});
参数:
Name | Type | Description |
---|---|---|
options | Object | ajax参数,参考 defaultOptions 和 jQuery ajax的参数 |
返回: 参考 jQuery ajax 返回值
Type Object
(static).syncAjax(url, typeopt, dataopt, successfnopt) → {Object}
同步ajax
示例:
//console output {name: "test json", used: "test ajax function"}
vjspUtils.ajax.syncAjax('testjson/data1.json','get',function(d){console.info(d)});
参数:
Name | Type | Attributes | Description |
---|---|---|---|
url | String | URL | |
type | String | optional | 请求方式(get|post) |
data | Object | optional | 发送到服务器的数据 |
successfn | function | optional | 回调函数 |
返回: 参考 jQuery ajax 返回值
Type Object
(static).asyncAjax(url, typeopt, dataopt, successfnopt) → {Object}
异步ajax
示例:
//console output {name: "test json", used: "test ajax function"}
vjspUtils.ajax.asyncAjax('testjson/data1.json','get',function(d){console.info(d)});
参数:
Name | Type | Attributes | Description |
---|---|---|---|
url | String | URL | |
type | String | optional | 请求方式(get|post) |
data | Object | optional | 发送到服务器的数据 |
successfn | function | optional | 回调函数 |
返回: 参考 jQuery ajax 返回值
Type Object
(static).jsonpAjax(url, dataopt, successfnopt, jsonpOptionsopt) → {Object}
See: vjspUtils.ajax.defaultOptions
跨域ajax (jsonp)
参数:
Name | Type | Attributes | Description |
---|---|---|---|
url | String | URL | |
data | Object | optional | 发送到服务器的数据 |
successfn | function | optional | 回调函数 |
jsonpOptions | Object | optional | jsonp相关设置,只能设置 jsonp和jsonpCallback |
返回: 参考 jQuery ajax 返回值
Type Object