JavaScript API

liquidAjaxCart.get()

A method of the liquidAjaxCart object, which initiates an Ajax request to the Shopify Cart API GET /cart.js endpoint.

Structure

The method takes an object with the request options as the first parameter:

const options = {
  firstCallback: function(requestState) {
    /**
     * This callback function will be called first after the request is performed,
     * thus none of request subscribers knows the result of the request,
     * thus Cart state is not updated yet, sections are not updated yet,
     * everything is not updated yet.
     */
  },
  lastCallback: function(requestState) {
    /**
     * This callback-function will be called the latest
     * among request subscribers,
     * thus all the request subscribers are executed,
     * thus Cart state is updated, sections are updated,
     * everything is updated.
     */
  },
  info: {
    /**
     * Any additional data you want to attach to the Request state object.
     * Don't use the "initiator" and the "cancel" keys.
     */
    myParameter: 'value'
  },

  // whether the request should go to the beginning of the queue rather than to the end
  important: false
}

liquidAjaxCart.get(options);

Options

The options parameter is an object, and it might have the following properties:

firstCallback

The firstCallback parameter is a callback function that will be called first after the request is performed and before any other callback functions, that are subscribed to the request, are called. Thus, this function will be called before Liquid Ajax Cart starts updating the liquidAjaxCart.cart object, the data-ajax-cart-section elements, the data-ajax-cart-bind elements, the global CSS classes.

The firstCallback function will be called with the only parameter — the Request state object.

The detailed explanation on when the firstCallback function is called, and what exactly happens before and after the call, is in the “Lifecycle, events, API” guide.

lastCallback

The lastCallback parameter is a callback function that will be called last after the request is performed and after any other callback functions, that are subscribed to the request, are called. Thus, this function will be called after Liquid Ajax Cart updates the liquidAjaxCart.cart object, the data-ajax-cart-section elements, the data-ajax-cart-bind elements, the global CSS classes.

The lastCallback function will be called with the only parameter — the Request state object.

The detailed explanation on when the lastCallback function is called, and what exactly happens before and after the call, is in the “Lifecycle, events, API” guide.

info

The info parameter is a JavaScript object that will be attached to the Request state object of the request. You can add your custom properties to the Request state using the info parameter.

Don’t use the initiator and the cancel keys as they are reserved properties.

important

If you want a request to go to the beginning of the Queues or Requests rather than to the end in order to execute it as soon as possible, set the important property to true.

Explore the feature and the use cases on the Queues or Requests page.