有没有一种方法可以将刷新持久性添加到进度条?

时间:2018-10-17 05:34:28

标签: javascript html

因此,我有一个进度条脚本,该脚本每次按下按钮时都会增加进度。 HTML:

<script>
function unlike(id){
    console.log('unlike');
    var id2 = toString(id).split('-');
    console.log('Unlike: '+id);
    console.log('split id: '+ id2);
    $.ajax({
        url: 'index.php?route=product/product/like_review',
        type: "get",
        data: {
            'is_liked': 1,
            'review_id': id[0],
            'customer_id': id[1],
            'product_id': id[2]
        },
        dataType: 'json',
        success: function(json) {
            console.log(json);
            $('.btn-thumbs-up').find('input[type=checkbox][name=review_like]').attr("onclick","like(id);");
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
    });
}

function like(id){
    console.log('like');
    console.log('Liked: '+id);
    var id2 = toString(id).split('-');
    console.log('split: '+id2);
    $.ajax({
        url: 'index.php?route=product/product/like_review',
        type: "get",
        data: {
            'is_liked': 0,
            'review_id': id[0],
            'customer_id': id[1],
            'product_id': id[2]
        },
        dataType: 'json',
        success: function(json) {
            console.log(json);
            $('.btn-thumbs-up').find('input[type=checkbox][name=review_like]').attr("onclick","unlike(id);");
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
    });
}

重新加载星期二页面时,是否可以保留进度条的数据?

1 个答案:

答案 0 :(得分:2)

如果只是刷新页面而不关闭窗口/选项卡,则可以使用sessionStorage

如果要获取数据,即使关闭了窗口/选项卡,也可以使用localStorage。但是请记住,完成后要删除数据,因为localStorage不会过期。

相关问题