Core Docs | Additional Modules Docs

sb.ajax


@Description: Used to send and receive data back to the originating server without leaving the page. See additional sb.ajax object prototype for more information
@File: sb.js
@Type: constructor
@Url: http://www.surebert.com/examples/ajax
@Example:
var aj = new sb.ajax({
url : '/some/url',
method : 'post', //optional
format : 'text', //optional
data : {
name : 'paul',
number : 6
},
onResponse : function(response){
alert(response);
}
});
aj.fetch();

sb.ajax.defaultFormat


@Description: The default way the ajax instances handles the data retreived from the scripts. This sets the default format for all sb.ajax instances that do not already specify a format. It is text by default but you can override this in your script. The options are;
1. text - returns the data from the server side script as text and passes it to the instances onResponse method
2. json - returns the data from the server side script as a JSON object whose properties can easily be accessed with javascript
3. xml - returns the data from the server side script as an XML node which can be parsed with traditional XML parsing methods in javascript
4. js - evaluated the data returned from the server side script as javascript
5. send - only sends data and does not receive any data
6. head - only reads the header data from the HTML transaction and passes that to the instances onResponse method. If a header property is specified on the sb.ajax instance, then only that header is passed
@File: sb.js
@Type: string
@Example:
sb.ajax.defaultFormat = 'text';

sb.ajax.defaultMethod


@Description: The default transport method used for communicating with server side scripts. If this is changed, all insatnces with non specified transport methods will use this one. It is 'post' by default.
@File: sb.js
@Type: string

sb.ajax.prototype.abort


@Description: You can use this to abort an ajax function that is fetching. In addition, if you have defined an onabort() method for your sb.ajax instance it will fire whenever the fetch is canceled.
@File: sb.js
@Type: function
@Example:
var myAjax = new sb.ajax({
        url : 'process.php'
    });
    myAjax.fetch();

    //aborts a fetch already in progress, you could attach this event to a cancel button
    myAjax.abort();

sb.ajax.prototype.abort


@Description: You can use this to abort an ajax function that is fetching. In addition, if you have defined an onabort() method for your sb.ajax instance it will fire whenever the fetch is canceled.
@File: sb.js
@Type: function
@Example:
var myAjax = new sb.ajax({
        url : 'process.php',
        onAbort : function(){
            alert('ajax call aborted');
        }
    });

    //aborts a fetch already in progress, you could attach this event to a cancel button, also used by timeout
    myAjax.abort();

sb.ajax.prototype.async


@Description: USe an asynchronous connection or not. This is optional
@File: sb.js
@Type: boolean
@Example:
myAjax.async = false;

sb.ajax.prototype.debug


@Description: Determines if the data sent and received is debugged to the to surebert debug consol which. This only works if you include sb.developer.js This makes debuggin much easier.
@File: sb.js
@Type: Boolean
@Example:
var myAjax = new sb.ajax({
        url : 'process.php',
        debug : 1
    });

    //or added afterwards with
    myAjax.debug =1;

sb.ajax.prototype.fetch


@Description: Sends any data specified to the external server side file specified in your instances .url property and returns the data recieved to the instance's onResponse method
@File: sb.js
@Type: function
@Example:
var myAjax = new sb.ajax({
        url : 'process.php'
    });

    //fetches the data from the url specified in the constructor
    myAjax.fetch();

sb.ajax.prototype.onHeaders


@Description: Fires when the ajax request gets it headers back
@File: sb.js
@Type: function
@Example:
var myAjax = new sb.ajax({
        url : 'process.php',
        onHeaders : function(status, statusText){
            //alert 400 if file not found
            alert(status);
            //you also have access to other headers
            alert(this.ajax.getResponseHeader('Content-Type'));
        }
    });

sb.ajax.prototype.onHeaders


@Description: Fires when the ajax request gets it headers back
@File: sb.js
@Type: function
@Example:
var myAjax = new sb.ajax({
        url : 'process.php',
        onHeaders : function(status, statusText){
            //alert 400 if file not found
            alert(status);
            //you also have access to other headers
            alert(this.ajax.getResponseHeader('Content-Type'));
        }
    });

sb.ajax.prototype.onResponse


@Description: Fires when the ajax request gets its response back from the server.
@File: sb.js
@Type: function
@Param: response String, json, or XML depending on ajax instance .format property
@Example:
var myAjax = new sb.ajax({
        url : 'process.php',
        onResponse : function(response){
            alert(response);
        }
    });

sb.ajax.prototype.timeout


@Description: The amount of time in milliseconds the ajax request will wait before it aborts. This is optional
@File: sb.js
@Type: integer
@Example:
myAjax.timeout = 1000;

    //fetches the data from the url specified
    myAjax.fetch();