• Stars
    star
    247
  • Rank 164,117 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An ajax library you need a microscope to see

nanoajax

An ajax library you need a microscope to see.

Weighs in at 620 bytes gzipped and minified. It is very basic, but contains support for cross-domain requests back to somewhat older browsers (See Compatibility).

API Changes

  • Passing a string url instead of a params object has been removed in v0.4.0
  • The params object was introduced in v0.2.1, and is the only way to use POST requests.
  • Passing a FormData object as the body will cause the Content Type header to not be set, as appropriate.

Install

You can use npm or bower:

npm install --save nanoajax
bower install --save nanoajax

Can be used via browserify or webpack:

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)

Use

GET

nanoajax.ajax({url:'/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
})

Documentation

var xhrRequest = nanoajax.ajax(params, callback)

Simple and small ajax function. Takes a parameters object and a callback function.

Parameters:

  • url: string, required
  • headers: object of {header_name: header_value, ...}
  • body:
    • string (sets content type to 'application/x-www-form-urlencoded' if not set in headers)
    • FormData (doesn't set content type so that browser will set as appropriate)
  • method: 'GET', 'POST', etc. Defaults to 'GET' or 'POST' based on body
  • cors: If your using cross-origin, you will need this true for IE8-9 (to use the XDomainRequest object, also see Compatibility)

The following parameters are passed directly onto the request object:

IMPORTANT NOTE: The caller is responsible for compatibility checking.

  • responseType: string, various compatability, see xhr docs for enum options
  • withCredentials: boolean, IE10+, CORS only
  • timeout: long, ms timeout, IE8+
  • onprogress: callback, IE10+

Callback function prototype:

  • statusCode: integer status or null
    • if request errors for some browsers (notably Chrome), this is 0 (and response is "Error")
  • response:
    • if responseType set and supported by browser, this is an object of some type (see docs)
    • otherwise if request completed, this is the string text of the response
    • if request is aborted, this is "Abort"
    • if request times out, this is "Timeout"
    • if request errors before completing (probably a CORS issue), this is "Error"
  • request object

Returns the request object. So you can call .abort() or other methods

Compatibility

nanoajax works on android, iOS, IE8+, and all modern browsers, with some (known) caveats.

  • Safari is conservative with cookies and will not allow cross-domain cookies to be set from domains that have never been visited by the user.
  • IE8 and IE9 do not support cookies in cross-domain requests in this library. There are other solutions out there, but this library has chosen small over edge case compatibility.

License

MIT found in LICENSE file.

More Repositories

1

itertools

A golang implementation of the python standard library module.
Go
296
star
2

golang-instagram

A minimalist golang instagram API wrapper
Go
74
star
3

golang-soundcloud

A SoundCloud API implementation in Go
Go
42
star
4

clj-kubernetes-api

Kubernetes API Client library in Clojure
Clojure
40
star
5

fyra

Experimental framework based on Functional Relational (not Reactive!) Programming
Clojure
30
star
6

kafka-connect-slack-sink

Kafka Connector Sink to post to slack via webhooks
Clojure
19
star
7

goauth2

OAuth 2.0 Implementation
Go
12
star
8

golang-spsa

Simultaneous Perturbation Stochastic Approximation method in Go
Go
11
star
9

gulp-packer

Minify JS using /packer/ with gulp
JavaScript
10
star
10

golang-mtgox

A Mt. Gox Websocket API Implementation in Go
Go
7
star
11

pebble-bold-hour

A pebble watchface with a bold hour and a small minute.
C
7
star
12

d3-tsp-demo

A Traveling Salesman Problem (TSP) solver using d3.js (demo)
7
star
13

kubernetes-linode-setup

Setting up a kubernetes cluster on linode
Shell
7
star
14

multipart-pipe

Pipe multipart uploads direct to S3 or another file service
JavaScript
5
star
15

franzy-connect

Clojurized Kafka Connect Interface
Clojure
5
star
16

tethr.io

A socket.io-like API for Peer to Peer WebRTC Data Streams
JavaScript
5
star
17

node-api-routes

A declarative system for creating express API routes.
JavaScript
4
star
18

kafka-connect-s3-sink

Kafka Connector that writes records to S3 as files
Clojure
4
star
19

haskell-kafka

An Apache Kafka driver in Haskell
Haskell
4
star
20

node-redis-eval

A small package to manage redis EVAL SCRIPT caching and EVALSHA calling
JavaScript
3
star
21

sicp-club

Book club to read SICP
Scheme
3
star
22

yanatan16.github.io

My website based on the Jekyll framework
SCSS
3
star
23

docker-autobuilder

Docker Automated builds support for private repositories
Lua
3
star
24

tybee

An asset trading system written in Haskell
Haskell
3
star
25

denvr

Development Environments Reimagined
Clojure
3
star
26

haskell-spsa

Simultaneous Perturbation Stochastic Approximation in Haskell
Haskell
3
star
27

pycodejam

A Code Jam problem runner for python
JavaScript
3
star
28

kafka-connect-pg-sink

Kafka Connector for pushing records as tuples in PostgreSQL
Clojure
3
star
29

cljs-node-app-template

Lein template for a clojurescript node app
Clojure
3
star
30

revealme

A cloud presentation format using reveal.js
CSS
3
star
31

node-fanin

A simple concurrency pattern: fan-in
JavaScript
3
star
32

talk-clojurescript-for-javascript-devs

Talk: Clojurescript for Javascript Developers
Clojure
3
star
33

RoboNUI

Robotic Natural User Interface using Kinect and COTS Robot Kits in C#
C#
3
star
34

mongodb-indexing-presentation

Content for a presentation on MongoDB Indexing.
Shell
2
star
35

gochat

A chat server in Go
Go
2
star
36

talk-frelp-ui

Talk: Functional Relational Programming in UI Development
HTML
1
star
37

minerva

Some old research on Predictive Optimal Investing
Python
1
star
38

hnefatafl

tafl for everyone
Clojure
1
star
39

mgoconf

Small configuration file reading for mgo
Go
1
star
40

haskell-pipes-wc

`wc` in haskell using pipes
Haskell
1
star
41

exchequer

An arbitrary object query utility belt for Go
Go
1
star
42

stripe-ctf3-level4

Solution to Stripe CTF3 Level 4: Distributed SQL Database
Python
1
star
43

pebble-binary

A pebble watchface which displays Month, Day, Hour, Minute, and Second in binary.
C
1
star
44

mongoose-pusher

Mongoose plugin to allow a "pusher" function which acts like setter for arrays.
JavaScript
1
star
45

node-marked-sections

A simple node package to parse markdown and insert sections around headings.
JavaScript
1
star
46

haskell-chp-wc

Implementation of `wc` in Haskell using CHP
Haskell
1
star
47

joneisen.works

Business Website
JavaScript
1
star
48

ProtoStat

Prototype Bench Processor Statusing, Scheduling, and Logging WebApp in php
PHP
1
star
49

react-simple-example

Simple react/redux with semantic ui example
JavaScript
1
star
50

twitter-graph-analysis

A few scripts to help analyze a twitter graph
Python
1
star
51

zuul-demo

A demo for node's zuul test runner
JavaScript
1
star
52

node-unix-listen

Simple but comprehensive unix socket listening for connect servers
JavaScript
1
star