Comparing version 0.1.1 to 0.1.2
@@ -17,6 +17,8 @@ function Alite(XMLHttpRequest) { | ||
ajax: function (opts) { | ||
var req = new XMLHttpRequest(); | ||
var promise = new Promise(function(resolve, reject) { | ||
return new Promise(function(resolve, reject) { | ||
var req = new XMLHttpRequest(); | ||
var data = opts.raw ? opts.data : (opts.data ? JSON.stringify(opts.data) : undefined); | ||
this.xhr = req; | ||
req.onreadystatechange = function () { | ||
@@ -48,5 +50,2 @@ if (req.readyState == 4) { | ||
}); | ||
promise.xhr = req; | ||
return promise; | ||
} | ||
@@ -53,0 +52,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
function Alite(t){function e(t){var e=t&&t.responseText,a=e&&("{"==e[0]||"["==e[0]);return a?JSON.parse(e):e}t=t||this.XMLHttpRequest;var a={ajaxStart:function(){},ajaxStop:function(){},ajax:function(n){var r=new t,o=new Promise(function(t,o){var s=n.raw?n.data:n.data?JSON.stringify(n.data):void 0;if(r.onreadystatechange=function(){4==r.readyState&&(r.status>=200&&r.status<300?t(e(r)):o(e(r)),a.ajaxStop(r,n))},r.open(n.method,n.url),!n.raw&&r.setRequestHeader("content-type","application/json"),n.headers)for(var u in n.headers)r.setRequestHeader(u,n.headers[u]);a.ajaxStart(r,n),n.ajaxStart&&n.ajaxStart(r),r.send(s)});return o.xhr=r,o}};return["put","post","patch","get","delete"].forEach(function(t){a[t]=function(e){return e.method=t,this.ajax(e)}}),a}"undefined"!=typeof module&&module.exports&&(module.exports=Alite); | ||
function Alite(t){function e(t){var e=t&&t.responseText,a=e&&("{"==e[0]||"["==e[0]);return a?JSON.parse(e):e}t=t||this.XMLHttpRequest;var a={ajaxStart:function(){},ajaxStop:function(){},ajax:function(n){return new Promise(function(r,o){var s=new t,u=n.raw?n.data:n.data?JSON.stringify(n.data):void 0;if(this.xhr=s,s.onreadystatechange=function(){4==s.readyState&&(s.status>=200&&s.status<300?r(e(s)):o(e(s)),a.ajaxStop(s,n))},s.open(n.method,n.url),!n.raw&&s.setRequestHeader("content-type","application/json"),n.headers)for(var i in n.headers)s.setRequestHeader(i,n.headers[i]);a.ajaxStart(s,n),n.ajaxStart&&n.ajaxStart(s),s.send(u)})}};return["put","post","patch","get","delete"].forEach(function(t){a[t]=function(e){return e.method=t,this.ajax(e)}}),a}"undefined"!=typeof module&&module.exports&&(module.exports=Alite); | ||
//# sourceMappingURL=alite.min.js.map |
{ | ||
"name": "alite", | ||
"main": "alite.js", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/chrisdavies/alite", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "alite", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Tiny ajax helper", | ||
@@ -5,0 +5,0 @@ "main": "alite.js", |
@@ -93,9 +93,10 @@ # Alite | ||
The promise object has a non-standard property attached to it: `xhr` | ||
The promise object has a non-standard property attached to it: `xhr` which can be accessed | ||
inside then/catch via `this.xhr`. | ||
```js | ||
var promise = alite.delete('users/24') | ||
alite.delete('users/24') | ||
.then(function (result) { | ||
console.log(result); // The JSON object received | ||
console.log(promise.xhr.getResponseHeader('Server')); // Get the XHR object from the promise | ||
console.log(this.xhr.getResponseHeader('Server')); // Get the XHR object from the promise | ||
}); | ||
@@ -112,3 +113,2 @@ ``` | ||
function upload(file, presigned) { | ||
var alite = Alite(); | ||
@@ -115,0 +115,0 @@ var data = new FormData(); |
Sorry, the diff of this file is not supported yet
10836
75