Ajax-amd is an ajax library
Ajax.js is a library that helps making ajax requests on modern (IE >= 10) browsers. This library uses amd structure.
Install with NPM: npm install elo7-ajax-amd
Elo7-ajax-amd depends on an amd implementation. We suggest async-define implementation for dependency lookup. You only need to install it with NPM and load elo7-ajax-amd file on your page.
.get(url, data [,callbacks] [,config])
Executes an ajax request using get
http method.
define(['ajax'], function(ajax) {
ajax.get('http://domain.com/ajax', {
'data': 'value'
}, {
'success': function(response [,xhr]) {
// success callback
},
'error': function(response [,xhr]) {
// error callback
},
'complete': function([xhr]) {
// complete callback
}
}, {
retries: 1, // number of retries
timeout: 1000, // timeout in ms
async: true // asynchronous
});
});
.post(url, data [,callbacks] [,config])
Executes an ajax request using post
http method.
define(['ajax'], function(ajax) {
ajax.post('http://domain.com/ajax', {
'data': 'value'
}, {
'success': function(response [,xhr]) {
// success callback
},
'error': function(response [,xhr]) {
// error callback
},
'complete': function([xhr]) {
// complete callback
}
}, {
retries: 1, // number of retries
timeout: 1000, // timeout in ms
async: true // asynchronous
});
});
.put(url, data [,callbacks] [,config])
Executes an ajax request using put
http method.
.delete(url, data [,callbacks] [,config])
Executes an ajax request using delete
http method.
.serializeObject(form)
Serializes form fields to json. It can be used as data to the ajax function.
define(['ajax'], function(ajax) {
var serializedForm = ajax.serializeObject(document.querySelector('form'));
});
Elo7-ajax-amd is released under the BSD. Have at it.
Copyright ©️ 2017 Elo7