xkr.us/code/javascript

Net - A simple, robust XMLHTTP interface

Net is an XMLHTTP connection management library meant to simplify JavaScript authors' dealings with the underlying code necessary to successfully make both GET and POST requests.

Obtaining

The latest version of the code will always be available from this page.

Net.js - (4.8KB) - 2006-08-29

Usage

Public Methods

get

post

Example Usage 1

var fnWhenDone = function(R) { alert(R.responseText); };
Net.get({url: "foo.xml", vars: "x=1&y=2", onsuccess: fnWhenDone});
      

Explanation

Probably the simplest invocation of Net.get() with a simple relative URL, a string of '&' delimited key=value pairs, and a callback function that simply alerts the responseText property of the R object.

Example Usage 2

var fnWhenDone = function(R) { alert(R.responseText); };
var fnWhenError = function(sType, R) { alert("Error! ("+sType+"): "+(R.statusText||'')); };
Net.post({url: "foo.php", vars: {x: 1, y: 2}, onsuccess: fnWhenDone, onerror: fnWhenError});
      

Explanation

A call to Net.post() that passes an object literal with key-value pairs for the vars and both a success and error handler.

Test Script

See test.html for a working implementation.

Private Methods

Net [constructor]

_createRequestObject

_fnErrorDefault

_serializeObject

_setCallback

Meta