Harnessing AJAX in Venddor IO

Venddor IO employs AJAX, a potent tool that enables seamless page content updates without necessitating a page refresh.

A Glimpse into Venddor IO's AJAX Mechanism

Venddor IO has crafted its unique extensions for the jQuery ajax method, which are stored in the js/tygh/ajax.js file. Here's a sequence of these methods:

  1. submitForm (exclusive to forms): Extracts form data and preps it for transmission.
  2. request: Dispatches an AJAX request to the relevant controller (deduced from dispatch). This utilizes the jQuery ajax method.
  3. response: Activated post the successful completion of a request. Manages the server's actual response and showcases the outcome.
  4. inProgress: Evaluates if an AJAX request is ongoing.
  5. clearCache: Erases the response cache.

Server-side, the AJAX request's handling is facilitated by the fn_init_ajax function (located in app/functions/fn.init.php). This process includes:

For server-side identification of AJAX requests, the AJAX_REQUEST constant is set to true.

To specify PHP code segments exclusively for AJAX requests, you can use the AJAX_REQUEST constant.

For example:

if (defined('AJAX_REQUEST')) {
    fn_set_notification('E', fn_get_lang_var('warning'), $msg, true, 'insecure_password');
}

Upon script execution completion for an AJAX request or when the exit() function is explicitly invoked, the AJAX class destructor (app/Tygh/Ajax.php) operates. This destructor conveys the display information to a JSON array, which is then forwarded to the response JS function in /js/tygh/ajax.js.

Response Structure

Typically, a controller in Venddor IO sends back a response in this structure:

data:
    notifications:
        id:
            text
            title
        ...
    html:
        block_id:
            block_content
        ...