按下后退按钮时未发送变量

时间:2013-02-14 23:27:54

标签: php javascript jquery html variables

我有一个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);
            });
        }
    });
});

有什么想法解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

在新窗口中打开项目描述,或者(更优雅地)在模态对话框中打开项目描述(例如,使用jQuery UI dialog)。