# The Ajax
Introduction:
All XMLHttpRequest really does is allows browsers to send messages back to the server. Combined with DOM manipulation, this allows us to update or replace parts of a page. This simple API marked a radical change in web application development, and rapidly became commonplace
The Siga.net
Using the examples above, I’ve built Siga.net which implements get, post, and ajax:
Siga.net.get('/example' , { success : function (r) { alert (r.responseText ); } });
The available chained methods are:
- set: set a HTTP header data.
- the postBody end: send the request over the network, and calls your callback with a res object.
- Send: sends the request and calls data: .send({ data: value }, function(res) { });
An Ajax GET request. Exemple:
S.get('/get-test')
.set('Accept', 'text/html')
.end(function(res) {
assert.equal('Sample text', res.responseText);
});
An Ajax POST request. Example:
S.post('/post-test')
.data({ key: 'value' })
.end(function(res) {
assert.equal('value', res.responseText);
});
A jsonp request. Example:
var url = 'http://feeds.delicious.com/v1/json/';
url += 'alex_young/javascript?callback={callback}';
Siga.net.jsonp(url, {
success: function(json) {
console.log(json);
}
});
The Ajax methods are mapped to the turing object:
- Siga.get();
- Siga.post();
- Siga.json();