1.2.2 • Published 5 years ago
steamer-net v1.2.2
steamer-net
ajax util for development
Options
- url - String request url
- type
- String param type. Pass json POST data to Ajax when set type as
json - default
'' json|''
- String param type. Pass json POST data to Ajax when set type as
- param
- Object
- jsonCbName String necessary if ajaxType is
JSONP - success - Function success callback
- error
- Function error callback
- errCode:
-1=>xhr.onerror,-2=>xhr.ontimeout
- errCode:
- timeout
- Integer timeout (unit: ms)
- ajaxType
- String ajax type
- default
GET-POST|GET|JSONP|FORM
- default
- dataType
- String returned data type
- default
json json|text|
- xhrFields
- Object
- {
withCredentials:
trueorfalse}
- headers
- Object request headers
- { 'Access-Control-Allow-Origin': '*' }
Functions
- net.ajaxInit
net.ajaxInit({
beforeRequest: function(opts) {
opts.param.xsrf = 'xsrf';
return opts;
},
beforeResponse: function(data, successCb, errorCb) {
data.foo = 'bar';
successCb(data);
},
dataReturnSuccessCondition: function(data) {
return !data.errCode;
},
});
dataReturnSuccessConditionwill invoked afterbeforeResponse
- net.ajax
net.ajax({
url: baseUrl + "get_material_info.fcg",
param: {
id: 1
},
ajaxType: 'POST',
success: function(data){
// some code
},
error: function(xhr){
// some code
}
});- net.ajaxGet
net.ajaxGet({
url: baseUrl + "get_material_info.fcg",
param: {
id: 1
},
success: function(data){
// some code
},
error: function(xhr){
// some code
}
});- net.ajaxPost
net.ajaxPost({
url: baseUrl + "get_material_info.fcg",
param: {
id: 1
},
success: function(data){
// some code
},
error: function(xhr){
// some code
}
})- net.ajaxJsonp
net.ajaxJsonp({
url: baseUrl + "get_material_info.fcg",
param: {
id: 1,
jsonCbName: "jsonpCb"
},
success: function(data){
// some code
},
error: function(xhr){
// some code
}
})Local data
If you would like to use local data, you can specify localData param.
net.ajaxPost({
url: baseUrl + "get_material_info.fcg",
param: {
id: 1
},
localData: [{id: 1, name: "a"}],
success: function(data){
// some code
},
error: function(xhr){
// some code
}
})Test
npm run test1.2.2
5 years ago
1.2.1
7 years ago
1.2.0
7 years ago
1.1.7
8 years ago
1.1.6
8 years ago
1.1.5
8 years ago
1.1.4
8 years ago
1.1.3
8 years ago
1.1.2
9 years ago
1.1.1
9 years ago
1.1.0
9 years ago
1.0.1
9 years ago
1.0.0
9 years ago
0.2.6
9 years ago
0.2.5
9 years ago
0.2.4
9 years ago
0.2.3
9 years ago
0.2.1
9 years ago
0.2.0
9 years ago
0.1.0
9 years ago