I’ve been struggling with this issue for a while now. I have OpenCart 1.5.2.1 installed, and during the checkout phase I have several steps that must complete in the background. While this is happening, I’m trying to displaying a simple ajax-loader.gif, and I want it to disappear once the page is done processing. At the moment, the ajax-loader.gif isn’t showing…
Here’s my javascript:
var el = $("#confirm .checkout-heading").addClass("loading");
$.ajax({
url: 'checkout/checkout.php',
success: function(data) {},
failure: function() {},
complete: function() {
el.removeClass("loading");
}
});
Stylesheet:
#confirm .checkout-heading {
background: #fff;
}
#confirm .checkout-heading.loading {
background-image: url('../image/ajax-loader.gif');
background-position: 98% 50%;
background-repeat: no-repeat;
}
Page:
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<h1><?php echo $heading_title; ?></h1>
<div class="checkout">
<div id="checkout">
<div class="checkout-heading"><?php echo $text_checkout_option; ?></div>
<div class="checkout-content"></div>
</div>
<?php if (!$logged) { ?>
<div id="payment-address">
<div class="checkout-heading"><span><?php echo $text_checkout_account; ?></span></div>
<div class="checkout-content"></div>
</div>
<?php } else { ?>
<div id="payment-address">
<div class="checkout-heading"><span><?php echo $text_checkout_payment_address; ?></span></div>
<div class="checkout-content"></div>
</div>
<?php } ?>
<?php if ($shipping_required) { ?>
<div id="shipping-address">
<div class="checkout-heading"><?php echo $text_checkout_shipping_address; ?></div>
<div class="checkout-content"></div>
</div>
<div id="shipping-method">
<div class="checkout-heading"><?php echo $text_checkout_shipping_method; ?></div>
<div class="checkout-content"></div>
</div>
<?php } ?>
<div id="payment-method">
<div class="checkout-heading"><?php echo $text_checkout_payment_method; ?></div>
<div class="checkout-content"></div>
</div>
<div id="confirm">
<div class="checkout-heading">Confirm Purchase</div>
<div class="checkout-content"></div>
</div>
</div>
Any help is appreciated. Thanks in advanced.
There are three possible reasons:
You are trying to get element before DOM is ready (use $(document).ready));
Ajax execution is too fast so you cant observe loader.
You’ve got troubles with css/image. To test it get rid of javascript and see if it works on static content (add class “loading” manually).
In the following example i’ve postponed execution of ajax for 2 secs :
http://jsfiddle.net/webdevel/Dd3B7/1/