2013-02-14 36 views
0

我有一個運行在一組複選框上的JavaScript過濾一些通過PHP顯示的項目。按下後不會發送變量按鈕

當有人過濾信息然後點擊一個項目時,他被引導到該項目的描述。我的問題是當用戶點擊瀏覽器中的BACK按鈕時,因爲我的過濾已經消失了。

發生這種情況是因爲我的腳本加載了一個.php文件,但只在DIV中(所以我不需要重新加載整個頁面)。這意味着我發送的變量只是在DIV級別加載,而不是在URL級別加載,所以當他們轉到特定產品的描述並返回時,這些變量不再存在,並且過濾消失。

這裏是我的JS:

$(function() { 
    $("input[type='checkbox']").on('change', function() { 
     var boxes = []; 
     // You could save a little time and space by doing this: 
     var name = this.name; 
     // critical change on next line 
     $("input[type='checkbox'][name='"+this.name+"']:checked").each(function() { 
      boxes.push(this.value); 
     }); 
     if (boxes.length) { 
      $(".loadingItems").fadeIn(300); 
      // Change the name here as well 
      $(".indexMain").load('indexMain.php?categ=<?php echo $category; ?>&'+this.name+'=' + boxes.join("+"), 
      function() { 
       $(".indexMain").fadeIn('slow'); 
       $(".loadingItems").fadeOut(300); 
      }); 

     } else { 
      $(".loadingItems").fadeIn(300); 
      $(".indexMain").load('indexMain.php?categ=<?php echo $category; ?>', function() { 
       $(".indexMain").fadeIn('slow'); 
       $(".loadingItems").fadeOut(300); 
      }); 
     } 
    }); 
}); 

任何想法來解決這個問題?

回答

0

要麼在新窗口中打開項目描述,要麼在模式對話框中打開項目描述(例如使用jQuery UI dialog)。