extend-ajax
Advanced tools
Comparing version 1.2.3 to 1.2.4
# Changes | ||
# 1.2.4 | ||
- Add an option: scope | ||
# 1.2.3 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "extend-ajax", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "an AJAX request library", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -129,16 +129,18 @@ # extend-ajax | ||
- async \<boolean> 默认值: true | ||
- host \<string> 服务器主机的地址,默认值: ''. | ||
- timeout \<number> 请求超时的响应时间,单位:ms.默认值:0,0的情况下不会触发响应超时事件 | ||
- cacheSize \<number> 设置缓存大小,默认值: 0 | ||
- cacheExp \<number> 设置缓存时间,单位:秒,默认值:300 | ||
- charset \<stirng> 设置传输数据的编码字符集,默认值: 'utf-8' | ||
- convert \<function> 在使用响应数据前,对其进行处理,之后通过then(({data}) => {...})或者on('success', ({data})=> {...}),我们获取的data就是这个convert函数返回给我们的。 | ||
- convert \<function> 在使用响应数据前,对其进行处理,之后通过then(({data}) => {...})或者on('success', ({data})=> {...}),我们获取的data就是这个convert函数返回给我们的。 | ||
- dev \<Boolean> 默认值: false。如果为true,则环境就是development,否则为production。 | ||
- host \<string> 服务器主机的地址,默认值: ''. | ||
- header \<object> 设置头信息。默认值: {'Content-Type': 'form', 'Accept': 'json'} | ||
- Content-Type \<string> 可以设置为: 'text', 'json', 'form'(default), 'formData', 'html' 以及标准的content-type。 | ||
- Accept \<string> 可以设置为: 'text', 'json', 'html'以及标准的Accept值。 | ||
- ... | ||
- jsonpName \<String> 处理jsonp响应的函数名称,默认值: 'jsonpCallback' | ||
- jsonpParma \<String> jsonp传输时回调函数的键名,default: 'callback' | ||
- scope \<object> 默认:null, 定义回调函数的作用域。 | ||
- timeout \<number> 请求超时的响应时间,单位:ms.默认值:0,0的情况下不会触发响应超时事件 | ||
- withCredentials \<boolean> 是否允许ajax请求携带验证信息,例如:cookie. | ||
- dev \<Boolean> 默认值: false。如果为true,则环境就是development,否则为production。 | ||
- header \<object> 设置头信息。默认值: {'Content-Type': 'form', 'Accept': 'json'} | ||
- Content-Type \<string> 可以设置为: 'text', 'json', 'form'(default), 'formData', 'html' 以及标准的content-type。 | ||
- Accept \<string> 可以设置为: 'text', 'json', 'html'以及标准的Accept值。 | ||
- ... | ||
@@ -145,0 +147,0 @@ ### ajax.form(id[,options]) |
@@ -131,4 +131,2 @@ # extend-ajax | ||
- async \<boolean> default: true | ||
- host \<string> host url,default: ''. | ||
- timeout \<number> the number of milliseconds a request can take before automatically being terminated | ||
- cacheSize \<number> set size of cache, default: 0 | ||
@@ -138,11 +136,14 @@ - cacheExp \<number> set the cache expiration time relative to the present, default: 300, unit: s. | ||
- convert \<function> pre-treat response data received, the function have one argument:response data.if set it, it must return a data handled,or when success event happen,we can't get data from res. | ||
- dev \<Boolean> default: false, if true, current environment is development,or else it is production. | ||
- host \<string> host url,default: ''. | ||
- jsonpName \<String> name of the callback functions that handle jsonp response,default: 'jsonpCallback' | ||
- jsonpParma \<String> name of the query string parameter to specify the callback,default: 'callback' | ||
- dev \<Boolean> default: false, if true, current environment is development,or else it is production. | ||
- header \<object> set http header.default: {'Content-Type': 'form', 'Accept': 'json'} | ||
- Content-Type \<string> you can set: 'text', 'json', 'form'(default), 'formData', 'html' and standard content-type value | ||
- Accept \<string> you can set: 'text', 'json', 'html' and standard Accept value | ||
- ... | ||
- scope \<object> default null, define the scope of callback function. | ||
- timeout \<number> the number of milliseconds a request can take before automatically being terminated | ||
- withCredentials \<Boolean> default: false, whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates | ||
- header \<object> set http header.default: {'Content-Type': 'form', 'Accept': 'json'} | ||
- Content-Type \<string> you can set: 'text', 'json', 'form'(default), 'formData', 'html' and standard content-type value | ||
- Accept \<string> you can set: 'text', 'json', 'html' and standard Accept value | ||
- ... | ||
### ajax.form(id[,options]) | ||
@@ -149,0 +150,0 @@ |
@@ -308,2 +308,3 @@ (function (global, factory) { | ||
responseText, | ||
scope = options.scope != null ? options.scope : null, | ||
convert = options.convert, | ||
@@ -316,3 +317,3 @@ res = {}; | ||
res.header = getHeader(xhr); | ||
res.data = isType(convert, 'function') ? convert(responseText) : responseText; | ||
res.data = isType(convert, 'function') ? convert.call(scope, responseText) : responseText; | ||
timer && clearTimeout(timer); | ||
@@ -568,7 +569,8 @@ if ((status >= 200 && status < 300) || status === 304) { | ||
var args = toArray(arguments), | ||
event = args.shift(); | ||
event = args.shift(), | ||
scope = options.scope != null ? options.scope : null; | ||
if (this.promise && this.resolve && (event === 'success' || event === 'fail')) { | ||
this.resolve(args[0]); | ||
this.resolve.call(scope, args[0]); | ||
} | ||
this['$' + event] && this['$' + event].apply(null, args); | ||
this['$' + event] && this['$' + event].apply(scope, args); | ||
// 请求失败 成功,都会触发end | ||
@@ -575,0 +577,0 @@ if (event !== 'progress' && event !== 'end' && event !== 'start') { |
35362
639
196