Skip to main content

AsyncBlockController

Purpose

AJAX load heavy content after the initial page load, while showing a placeholder.

Actions

ActionPurpose
--

Targets

TargetPurposeDefault
replace (Optional)The element to replace when the fetch request succeedthe controller root element

Classes

ClassPurposeDefault
---

Values

ValueTypeDescriptionDefault
endpointStringThe URL to fetch content from-
errorMessage (Optional)StringThe error message to display when the remote content fails to loadThis content failed to load
selector (Optional)StringThe CSS selector to use to extract the desired element(s) from the returned HTML responseEmpty. The entire HTML response will be loaded
maxRetries (Optional)NumberHow many times the controller should retry fetching the content in the event of network errors or bad responses1

Events

EventWhenDispatched onevent.detail
async-block:successWhen the content is fetch successfullythe controller root element-
async-block:errorWhen the block fails to get a response from the endpointthe controller root element-
async-block:completeWhen the request finishes, regardless of success or failurethe controller root element-

Side Effects

None

How to Use

The controller will send out a fetch request, and on success will replace the block with the HTML content of the response.

See Also

Lazy Block Controller Load Block Controller Poll Block Controller