monsieurbiz/mbiz_ajax

Magento 模块,增加了某些 AJAX 功能。

安装: 34

依赖: 1

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 0

类型:magento-module

0.1.0 2016-07-22 19:42 UTC

This package is auto-updated.

Last update: 2024-08-29 04:31:23 UTC


README

此模块如果请求是通过 AJAX 调用来执行的,则添加 AJAX_ 处理器。

它还添加了简单的 JSON 响应,用于分类视图。

如果您想让它工作,必须编写自己的 AJAX。

JavaScript 示例

(function ($) {
  $(document).ready(function () {
    // Catalog Category View
    if ($('.catalog-category-view').length) {

      // If we have a load more button
      var $more = $('.js-load-more');
      if ($more.length) {

        // On click on this button
        $more.click(function () {

          // Call the next page url in ajax
          var pagerData = {};
          pagerData[$more.attr('data-page-var-name')] = $more.attr('data-next-page');
          $.getJSON(
            {
              url: $more.attr('data-url'),
              dataType: 'json',
              data: pagerData,
              success: function (data) {

                // Disable if last page
                if (data.is_last_page) {
                  $more
                    .attr('disabled', true)
                    .addClass('disabled')
                  ;
                }

                // Insert products
                $('.product-list').append(data.body);

                // Update next page
                $more.attr('data-next-page', data.next_page);
              }
            }
          );

        });
      }
    }
  });
})(jQuery);

您也可以使用处理器在 AJAX 模式下对页面进行一些更新。

示例

<AJAX_catalog_category_view>
    <reference name="product_list">
        <!-- Change template of the product list -->
        <action method="setTemplate">
            <template>catalog/product/list_ajax.phtml</template>
        </action>
    </reference>
</AJAX_catalog_category_view>