jQuery的/阿贾克斯饼干饼干、jQuery、阿贾克斯

2023-09-10 21:39:07 作者:⊕シ狂野狩猎者

我用下面的code,以提高我的PHP / MySQL的拉式通过更多按钮,结果数量。

I'm using the below code in order to increase the number of results that my php/mysql pulls-in through a 'more' button.

我的问题是:我可以添加一个jQuery的cookie,这样,当更多按钮是pressed,多结果加载,当前状态保存?

My question is: Can I add a jquery cookie so that when the 'more' button is pressed, and more results are loaded, the current state is saved?

结果问题列包含链接到他们各自的文章内容。唯一的问题是,当你查看从更多结果的文章,然后返回到上市的结果页面,即由AJAX(更多 - press.php)被带来的结果都不见了:(

The results in question are listed elements which contain links to their respective article. The only problem is that when you view an article from the 'more' results, and then go back to the listed results page, the results that were brought in by the ajax (more-press.php) are gone : (

因此​​我的问题。希望这是有道理的。提前致谢。秒。

Hence my question. Hope it makes sense. Thanks in advance. S.

$(document).ready(
function(){                                        
        $(function() {
        //More Button
        $('.more').live("click",function() 
        {
        var ID = $(this).attr("id");
        if(ID)
        {
        $("#more"+ID).html('<img src="images/more_press.gif" alt="More results..." />');
        $.ajax({
        type: "POST",
        url: "more_press.php",
        data: "lastmsg="+ ID, 
        cache: false,
        success: function(html){
        $("div#updates").append(html);
        $("#more"+ID).remove();
                }
            });
        } else {
        $(".morebox").html('<p><strong>No more results...</strong></p>');
        }
        return false;
                });
            });
        })

编辑:也有这方面的相关职位 - 问题2

推荐答案

当然,你可以做到这一点。使用的jQuery插件的cookie 设置cookie时,点击更多按钮,加载更多的结果,例如:

Sure, you can do this. Use the jquery cookie plugin to set a cookie when they click the "more" button and load more results, e.g.:

// set cookie to expire in 60 minutes when 'more' is clicked
$.cookie('viewing_expanded_content',true, {
    expires : new Date(new Date().valueOf() + 60 * 60 * 1000)
});

而当他们返回到文章列表,可以检查服务器端的cookie中,服务的完整列表最初,或检查在使用JavaScript客户端的cookie presence并获取附加如果内容cookie的值设置为真:

And when they return to the list of articles, either check for the cookie on the server side and serve the full list initially, or check for the presence of the cookie on the client side using Javascript and fetch the additional content if the cookie's value is set to 'true':

if($.cookie('viewing_expanded_content')) {
  // make your ajax call, etc
}

希望有所帮助。

Hope that helps.