I have a tab-based set-up, with the tab content being loaded asynchronously.
<nav>
<ul>
<li><a href="/default" class="handle current" data-handle="default">OVERVIEW</a></li>
<li><a href="/services" class="handle" data-handle="services">SERVICES</a></li>
<li><a href="/clients" class="handle" data-handle="clients">CLIENTS</a></li>
</ul>
</nav>
</div>
<div class="tab selected" data-handle="default" data-populated="true">Some stuff in here.</div>
<div class="tab unselected" data-handle="services" data-source="/services-snipet" data-populated="false"></div>
<div class="tab unselected" data-handle="clients" data-source="/clients-snipet.html" data-populated="false"></div>
</div>
I have attached events to the handle
class, so that it can move the current
class and switch selected
/unselected
classes appropriately. However, before it makes that switch, it checks dataset["populated"]
on the new tab. If this is false
, it will load the dataset["source"]
via AJAX and populate.
Additionally, I am using event.preventDefault()
as part of the process, so as not to follow the link on the tab itself.
All of that is working just fine.
The issue is that I want to be able to retrigger the default event - the link - if the AJAX request fails, or times out. Is there some way of suspending/delaying the default event until I have the asynchronous AJAX response, so can decide then if I want to prevent it or not? Is there an alternate mechanism that would allow me to prevent it at the beginning, then retrigger it when I get an AJAX failure or time-out? Or is my only choice to read the href of this
and redirect the page in the failure case?
(no jQuery, please)