1.2.2 • Published 3 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:
true
orfalse
}
- 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;
},
});
dataReturnSuccessCondition
will 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 test
1.2.2
3 years ago
1.2.1
6 years ago
1.2.0
6 years ago
1.1.7
6 years ago
1.1.6
6 years ago
1.1.5
6 years ago
1.1.4
6 years ago
1.1.3
6 years ago
1.1.2
7 years ago
1.1.1
7 years ago
1.1.0
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago
0.2.6
7 years ago
0.2.5
7 years ago
0.2.4
7 years ago
0.2.3
7 years ago
0.2.1
8 years ago
0.2.0
8 years ago
0.1.0
8 years ago