在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:galeone/sa开源软件地址:https://github.com/galeone/sa开源编程语言:JavaScript 100.0%开源软件介绍:sa - Simple AJAXThe aim of sa is to provide a lightweight library to easy make AJAX requests. Learning by examplesInstantiate the AJAX objectvar ajax = null;
try {
ajax = new AJAX();
} catch(e) {
// handle error (XMLHttpRequest object not supported)
} Instantiate the AJAX object for a CORS requestvar ajax = null;
try {
var CORS = true;
ajax = new AJAX(CORS);
} catch(e) {
// handle error (XMLHttpRequest object not supported)
} GET requestajax.get('/somepage?parmeter=wat&who=yello',function(data) {
// handle completed get request
},
function(statusCode) { // Handle failure
console.log(statusCode);
}); POST requestajax.post('/somepage', function(data) {
// Handle completed post request
}, function(statusCode) { // Handle failure
console.log(statusCode);
}, parameters); GET Request returning JSONajax.getJSON('/somepage?parmeter=wat&who=yello',function(data) {
// Handle json return object, like:
console.log(data.field1, data.field2);
}, function(statusCode) { // Handle failure
console.log(statusCode);
}); Generic requestYou can build your own request. ajax.request({
url: '/wow',
type: 'post',
dataType: 'json',
data: {wow: 'amazing', 'param2': 1},
success: function(json) {
alert(json.responseField2);
},
failure: function(statusCode) {
alert("Request failed with status code: " + statusCode);
}
}); In the example above we do a POST request to /wow and we expect to obtain a JSON object in respose. We could specify JSON or XML for the expected format of the response. Empty field means HTML. ParametersAs you can see from the examples, you can use JSON object or a literal string to pass parameters. To specify other parameters in //define generic ajax request parameter
{
type: '',
url: '',
data: '',
dataType: '',
success: function(data){},
failure: function(errorCode){}
}; With:
Licensesa is licensed under the terms of MIT licence. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论