TDI - Javascript API

Parts

API methods

Examples of usage

TDI.Ajax.send($("#buy-link"), {
    end : function() {
        alert("Thank you.");  
    }
});
 
TDI.Ajax.Request.send("/path/to/action", {
    method : "POST"
});

API events

TDI uses so-called Custom events for notifications about TDI process flow. Events in TDI can be separated into two groups:

Events usage

$(document).on("tdi:ajax:start", function(evt, data) {
    // evt - Event object
    // data - Additional data  
});

Preventing of the default action

Some events allow preventing the default behaviour:

$(document).on('tdi:ajax:beforeLinkClick', 'a',  function(evt, data) {
    evt.preventDefault();

    // Set custom HTTP headers and then send the request manually
    TDI.Ajax.send(evt.target, {
        beforeStart : function(xhr, settings, ajaxOptions) {
            xhr.setRequestHeader('X-Foo', 'Bar');
            return true; // allow the TDI sending process to go on
        }
    });
});
$(document).on("tdi:ajax:beforeFormSubmit", function(evt, data) {
    evt.preventDefault(); // prevent the default action, eg. submiting the form
    
    // process form data
    // set http headers
    // send form some other way
    // ...
});