tmt.net

tmt.net is a JavaScript library that abstracts the use of XMLHttpRequest and manages HTTP requests using Ajax. It's lightweight, rock-solid and offers some unique features

What's different in tmt.net?. Why do we need yet another XMLHttpRequest library?

HTTP requests issues by tmt.net contain "tmt.net" as the X-Requested-With header

tmt.net is also used as an helper for CSI and Ajaxform

In order to use this library you need tmt_net.js

Samples

API

tmt.net.httpRequest() Perform an HTTP request. You can either use a list of arguments or a single object containing name/value pairs. While using a list of arguments tends to be simpler, the single object argument gives you more flexibility

Available arguments using list:
  1. url. String (required)
  2. loadCallback. Function name (required)
  3. errback. Function name
  4. method. String (POST, GET or HEAD)
  5. params. An object containing name value pairs

Available arguments using object:

  • url. String (required)
  • loadCallback. Function name (required)
  • errback. Function name
  • method. String (POST, GET or HEAD)
  • params. An object containing name value pairs
  • contentType. String
  • timeout. Number of milliseconds. Default to 60000 (60 seconds)
  • headers. An array of objects with name/value pairs
  • contextData. This is a very special kind of argument, an object where the caller can store any arbitrary content that will be available inside the callback

See sample

Inside callbacks you can access:

  • this.response.responseText: HTTP response as text
  • this.response.responseXML: HTTP response as XML (if any)
  • this.response.status: HTTP status code
  • this.response.statusText: HTTP status text
  • this.response.url: url
  • this.response.allResponseHeaders: whole HTTP response header as a single string
  • this.response.contextData: any arbitrary content specified using the contextData argument (see above)
tmt.net.isSupported() Returns true if the current browser is supported by the library, false otherwise
request.abort() You can programmatically abort an ongoing HTTP request like:
var req = tmt.net.httpRequest("myurl.html",myCallback);
req.abort();
(see sample)

Gotchas