All over again.
$ git clone git://github.com/ded/reqwest.git reqwest
$ cd !$
$ npm install --dev
$ make
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/json'
, type: 'json'
, method: 'post'
, data: { [ name: 'foo', value: 'bar' ], [ name: 'baz', value: 100 ] }
, 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)
}
})
$ npm test
- IE6+
- Chrome 1+
- Safari 3+
- Firefox 1+
- Opera
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()
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!