Deprecated: This repository is deprecated. But if anyone wants to take over feel free to clone and go from there.
Simple plugin to Ajax Request
Passing options only.
var myrequest = new xRequest({
url: 'server.php',
type: 'post',
dataType: 'json',
onSuccess: function(json) {
console.log(json);
}
});
myrequest.send();Or passing two params, a form for serialize it's fields and options.
var myrequest = new xRequest($('#myform'), {
url: 'server.php',
type: 'post',
dataType: 'json',
processForm: true,
data: {foo: 'bar'},
onSuccess: function(json) {
console.log(json);
}
});
myrequest.send();Install with Bower
bower install xrequest --savexRequest live demo
url: './'- URL to send.type: 'post'- Send Method.dataType: 'json'- Data type to retrieve.csrf: true- If true, csfr token will send as http header.processForm: true- If true, serialize the form passed as param onnew xRequest(myform)data: null- The data to send. It will be to preserved until it decides to unset. For example using theunsetDataBy()orclearData()functions.
Note: The options by xRequest are compatible with jQuery.ajax options, so for example it can use: cache, jsonp, beforeSend or any options supported in jQuery.ajax function.
isSending()- Checks if it's sending yet.send()- Sends the ajax request.setOption(opt, value)- Sets one option. e.g:myrequest.setOption('url', '/server.php')setForm(form)- Sets the form. e.g:myrequest.setForm($('#myform'))getOption(opt)- Gets one option. e.g:myrequest.getOption('data')setData(key, value)- Sets a param data passing key and value or a hash object. E.g:setData({key1: val1, key2: val2})
Note:setDataadds or update the elements (key or value) in array data, it does not replace the array data itself.unsetDataBy(key)- Unsets one element data by key. e.g:myrequest.unsetDataBy('myparam')clearData()- Unsets all data values.getForm()- Gets current Form element instance.- The same toremoveDataElement(key)unsetDataBymethod (old)
onStart()- Fires when start the sending.onSuccess(data, textStatus, jqXHR)- Fires when request is ok.onError(jqXHR, textStatus, errorThrown)- Fires when an error occurred.
Check out the releases changelog.
Released under MIT Licence