@fdaciuk/ajax
Advanced tools
Comparing version 3.0.0 to 3.0.1
/**! | ||
* ajax - v3.0.0 | ||
* ajax - v3.0.1 | ||
* Ajax module in Vanilla JS | ||
* https://github.com/fdaciuk/ajax | ||
* Tue Sep 18 2018 12:49:49 GMT-0300 (-03) | ||
* Tue Sep 18 2018 12:56:28 GMT-0300 (-03) | ||
* MIT (c) Fernando Daciuk | ||
*/ | ||
!function(e,t){"use strict";"function"==typeof define&&define.amd?define("ajax",t):"object"==typeof exports?exports=module.exports=t():e.ajax=t()}(this,function(){"use strict";function e(e){var r=["get","post","put","delete"];return e=e||{},e.baseUrl=e.baseUrl||"",e.method&&e.url?n(e.method,e.baseUrl+e.url,t(e.data),e):r.reduce(function(r,o){return r[o]=function(r,u){return n(o,e.baseUrl+r,t(u),e)},r},{})}function t(e){return e||null}function n(e,t,n,u){var c=["then","catch","always"],i=c.reduce(function(e,t){return e[t]=function(n){return e[t]=n,e},e},{}),f=new XMLHttpRequest,p=r(t,n,e);return f.open(e,p,!0),f.withCredentials=u.hasOwnProperty("withCredentials"),o(f,u.headers,n),f.addEventListener("readystatechange",a(i,f),!1),f.send(s(n)?JSON.stringify(n):n),i.abort=function(){return f.abort()},i}function r(e,t,n){if("get"!==n.toLowerCase()||!t)return e;var r=i(t),o=e.indexOf("?")>-1?"&":"?";return e+o+r}function o(e,t,n){t=t||{},u(t)||(t["Content-Type"]=s(n)?"application/json":"application/x-www-form-urlencoded"),Object.keys(t).forEach(function(n){t[n]&&e.setRequestHeader(n,t[n])})}function u(e){return Object.keys(e).some(function(e){return"content-type"===e.toLowerCase()})}function a(e,t){return function n(){t.readyState===t.DONE&&(t.removeEventListener("readystatechange",n,!1),e.always.apply(e,c(t)),t.status>=200&&t.status<300?e.then.apply(e,c(t)):e["catch"].apply(e,c(t)))}}function c(e){var t;try{t=JSON.parse(e.responseText)}catch(n){t=e.responseText}return[t,e]}function i(e){return s(e)?f(e):e}function s(e){return"[object Object]"===Object.prototype.toString.call(e)}function f(e,t){return Object.keys(e).map(function(n){if(e.hasOwnProperty(n)&&void 0!==e[n]){var r=e[n];return n=t?t+"["+n+"]":n,null!==r&&"object"==typeof r?f(r,n):p(n)+"="+p(r)}}).filter(Boolean).join("&")}function p(e){return encodeURIComponent(e)}return e}); |
{ | ||
"name": "@fdaciuk/ajax", | ||
"description": "Ajax module in Vanilla JS", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"main": "dist/ajax.min.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -55,3 +55,3 @@ # Ajax | ||
```html | ||
<script src="//cdn.rawgit.com/fdaciuk/ajax/v3.0.0/dist/ajax.min.js"></script> | ||
<script src="//cdn.rawgit.com/fdaciuk/ajax/v3.0.1/dist/ajax.min.js"></script> | ||
``` | ||
@@ -140,4 +140,6 @@ | ||
If `content-type` is not passed, `application/x-www-form-urlencoded` will be used. | ||
If `content-type` is not passed, `application/x-www-form-urlencoded` will be used when you pass `data` as a _query string_. | ||
Passing `data` as `object`, `application/json` will be automatically used (_since v3.0.0_). | ||
**Note about uploads:** | ||
@@ -194,2 +196,14 @@ | ||
`data` might be a complex object, like: | ||
```js | ||
ajax().post('/api/new-post', { | ||
slug: 'my-new-post', | ||
meta: { | ||
categories: ['js', 'react'], | ||
tags: ['code'] | ||
} | ||
}) | ||
``` | ||
### `put(url, [data])` | ||
@@ -196,0 +210,0 @@ |
182277
313