API Docs for:
Show:

Ajax Class

Defined in: latest/ajax.js:7
Module: AJAX
Parent Module: JSFramework

Create a new AJAX requester.

Constructor

Ajax

(
  • url
  • options
)

Defined in latest/ajax.js:7

Parameters:

  • url String

    URL to load

  • options Object

    Options, which may consist of the following:

    • method: POST or GET
    • onSuccess, onFailure, onComplete: Callbacks for when the specified event happens
    • format: json or text, format to interpret result as
    • data: GET or POST data to send when doing request
    • context: What "this" should be when callback is called

Example:

// Basic GET request:
var request = new Ajax('test.php',
{
    onSuccess: function(data)
    {
        console.log(data);
    }
});
request.send();
// POST request
// Uses Util.buildQueryString to encode POST data. Arrays and hashes are sent using PHP syntax
(new Ajax('test.php',
{
    data:
    {
        'hello': 'world',
        // Supports arrays
        'arrayTest': [1, 2, 3, 4, 5],
        // Supports hashes
        'hashText': 
        {
            'awesome': true,
            'something': 'else'
        }
    },
    onSuccess: function(data)
    {
        console.log(data);
    }
})).send();

// Alternatively, the data can be passed to the send() method directly:
(new Ajax('test.php',
{
    onSuccess: function(data)
    {
        console.log(data);
    }
})).send({hello: 'world'});

Item Index

Properties

Methods

_getXHR

() private

Defined in latest/ajax.js:189

Internal function, get an XMLHttpRequest object

Returns:

XMLHttpRequest object

_onComplete

(
  • xhr
  • requestId
)
private

Defined in latest/ajax.js:154

Internal function, called when request completes

Parameters:

  • xhr XMLHttpRequest

    XHR object used to send request

  • requestId Integer

    Request ID

send

(
  • data
)

Defined in latest/ajax.js:118

Send this AJAX request

Parameters:

  • data Object

    Query string data to send, optional.

Properties

currentRequest

XMLHttpRequest private

Defined in latest/ajax.js:71

Current request, if any

options

Object

Defined in latest/ajax.js:79

Options for the AJAX request

requestCount

Integer private static

Defined in latest/ajax.js:99

Count of how many requests have been done

requests

Object private static

Defined in latest/ajax.js:107

All the currently executing requests

url

String

Defined in latest/ajax.js:65

URL the request will be to