browser asynchronous http requests
Pull request Compare This branch is 196 commits behind ded:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
make
src
tests
.gitignore
Makefile
Makefile.js
README.md
package.json
reqwest.js
reqwest.min.js

README.md

It's AJAX

All over again.

The happs

$ git clone git://github.com/ded/reqwest.git reqwest
$ cd !$
$ npm install --dev
$ make

API

reqwest('path/to/html', function (resp) {
  qwery('#content').html(resp)
})
reqwest({
    url: 'path/to/html'
  , method: 'post'
  , data: { foo: 'bar', baz: 100 }
  , success: function (resp) {
      qwery('#content').html(resp)
    }
})
reqwest({
    url: 'path/to/html'
  , method: 'get'
  , data: { [ name: 'foo', value: 'bar' ], [ name: 'baz', value: 100 ] }
  , success: function (resp) {
      qwery('#content').html(resp)
    }
})
reqwest({
    url: 'path/to/json'
  , type: 'json'
  , method: 'post'
  , error: function (err) { }
  , success: function (resp) {
      qwery('#content').html(resp.content)
    }
})
reqwest({
    url: 'path/to/data.jsonp?callback=?'
  , type: 'jsonp'
  , success: function (resp) {
      qwery('#content').html(resp.content)
    }
})
reqwest({
    url: 'path/to/data.jsonp?foo=bar'
  , type: 'jsonp'
  , jsonpCallback: 'foo'
  , success: function (resp) {
      qwery('#content').html(resp.content)
    }
})

The Tests

$ npm test

Browser support

  • IE6+
  • Chrome 1+
  • Safari 3+
  • Firefox 1+
  • Opera

Ender Support

Reqwest can be used as an Ender module. Add it to your existing build as such:

$ ender add reqwest

Use it as such:

$.ajax({ ... })

Serialize things:

$(form).serialize() // returns query string -> x=y&...
$(form).serialize({type:'array'}) // returns array name/value pairs -> [ { name: x, value: y}, ... ]
$(form).serialize({type:'map'}) // returns an object representation -> { x: y, ... }
$(form).serializeArray()
$.toQueryString({
    foo: 'bar'
  , baz: 'thunk'
}) // returns query string -> foo=bar&baz=thunk

Or, get a bit fancy:

$('#myform input[name=myradios]').serialize({type:'map'})['myradios'] // get the selected value
$('input[type=text],#specialthing').serialize() // turn any arbitrary set of form elements into a query string

Happy Ajaxing!