Ajax-loader.gif在页面加载后结束

时间:2012-04-09 14:35:59

标签: php javascript ajax jquery

我一直在努力解决这个问题。我安装了OpenCart 1.5.2.1,在结账阶段我有几个必须在后台完成的步骤。当这种情况发生时,我正在尝试显示一个简单的ajax-loader.gif,并且我希望它在页面处理完毕后消失。目前,ajax-loader.gif没有显示......

这是我的javascript:

  var el = $("#confirm .checkout-heading").addClass("loading");
  $.ajax({
      url: 'checkout/checkout.php',
      success: function(data) {},
      failure: function() {},
      complete: function() {
          el.removeClass("loading");
      }
  });

样式表:

#confirm .checkout-heading {
    background: #fff;
}
#confirm .checkout-heading.loading {
    background-image: url('../image/ajax-loader.gif');
    background-position: 98% 50%;
    background-repeat: no-repeat;
}

页:

  <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>

感谢任何帮助。谢谢你提前。

1 个答案:

答案 0 :(得分:1)

有三个可能的原因:

  1. 您正在尝试在DOM准备好之前获取元素(使用$(document).ready));

  2. Ajax执行速度太慢,因此您无法观察加载程序。

  3. 你遇到了css / image问题。测试它摆脱javascript并查看它是否适用于静态内容(手动添加类“加载”)。

  4. 在下面的例子中,我推迟了执行ajax 2秒:

    http://jsfiddle.net/webdevel/Dd3B7/1/