An ajax library you need a microscope to see.
Weighs in at 415 bytes gzipped, 623 bytes minified. It is very basic, but cross-browser compatible
NOTE: The POST
api has changed in version v0.2.1, see second example below for details.
The latest release (v0.2.1) includes custom header support but is larger than the previous release, v0.1.1.
Can be used via browserify:
npm install nanoajax
var nanoajax = require('nanoajax')
Or you can use the global script:
<script src="/nanoajax.min.js"></script>
(You can build that script with: npm install -g uglify-js && ./make
)
GET
nanoajax.ajax('/some-get-url', function (code, responseText) { ... })
POST
nanoajax.ajax({url: '/some-post-url', method: 'POST', body: 'post=content&args=yaknow'}, function (code, responseText, request) {
# code is response code
# responseText is response body as a string
# request is the xmlhttprequest, which has `getResponseHeader(header)` function
})
url
requiredmethod
"GET", "POST", "PUT", etc
body
string body (if its not url-encoded, make sure to setContent-Type
header)headers
header objectwithCredentials
true or false
only applicable to CORS (does not work in IE)
nanoajax
works on android, ios, IE8+, and all modern browsers.
CORS Note: nanoajax
does not support IE8 cross-domain requests.
MIT found in LICENSE
file.