July 23, 2013 by Patrick Altman / Technical

Timeouts and Intervals in eldarion-ajax

Sometimes you want an AJAX request triggered by time. With eldarion-ajax it is as easy as setting a few attributes in your markup.

There are two forms of timers that eldarion-ajax exposes via a couple of data attributes. The first is Javascript's setTimeout which executes once after a delay. The other is setInterval which repeatedly executes at a prescribed interval of time.

Both are very simple to wire up with eldarion-ajax as of the 0.10.0 release.

Example of using a timeout:

<body data-timeout="2000" data-url="/fetch/content/" data-replace-inner=".alert">
    <div class="alert"></div>

This will fetch content from /fetch/content/ after 2 seconds and load it in the div.alert.

Example of using an interval:

<body data-interval="1000" data-url="/fetch/counter/" data-replace-inner=".counter">
    <div class="counter"></div>

This will fetch content from /fetch/counter/ every 1 second and load it in the div.counter.

bootstrap-ajax renamed to eldarion-ajax django-waitinglist, A Pre-Launch Toolkit

Want to talk with us about something more custom or have questions?

Get in touch with us