簡體   English   中英

Opencart Ajax過濾器適用於產品

[英]Opencart Ajax filter For products

過濾器包含精煉搜索按鈕,頁面根據搜索加載產品。但是當我選中產品應該顯示的復選框時我想要。這可以通過ajax實現。

opencart 2.1.0.2產品過濾器的原始腳本

`<script type="text/javascript"><!--
$('#button-filter').on('click', function() {
    filter = [];

    $('input[name^=\'filter\']:checked').each(function(element) {
        filter.push(this.value);
    });

    location = '<?php echo $action; ?>&filter=' + filter.join(',');
});
//--></script> 
`

我嘗試使用ajax

`$(document).on('change','.sort_rang',function(){
    filter = [];

    $('input[name^=\'filter\']:checked').each(function(element) {
        filter.push(this.value);
    });
   location = '<?php echo $action; ?>&filter=' + filter.join(',');

   $.ajax({
     type: "POST",
     location: location,
     success: function(data)
     {                  
        $('.products-block').html(data);
     }               
   });
   console.log;
  return false;
});`

我得到了理想的結果。但它加載了整個頁面。 如果可能的話,我怎樣才能使用任何裝載機。

location是全局的並更改瀏覽器URL。 要避免使用全局location您需要使用var定義location

$(document).on('change','.sort_rang',function(){
    filter = [];

    $('input[name^=\'filter\']:checked').each(function(element) {
        filter.push(this.value);
    });
   var location = '<?php echo $action; ?>&filter=' + filter.join(',');

   $.ajax({
     type: "POST",
     location: location,
     success: function(data)
     {                  
        $('.products-block').html(data);
     }               
   });
   console.log;
  return false;
});

這只是代碼中的一點變化。在成功功能中,我刪除了特定的ID及其工作正常

   <script type="text/javascript">
$(document).on('change','.sort_rang',function(){
    filter = [];

    $('input[name^=\'filter\']:checked').each(function(element) {
        filter.push(this.value);
    });
   location = '<?php echo $action; ?>&filter=' + filter.join(',');

   $.ajax({
     type: "POST",
     location: location,
     success: function(data)
     {                  
        html(data);
     }               
   });
   console.log;
  return false;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM