jQuery的/阿贾克斯饼干PT2 [英] Jquery/Ajax cookie pt2

查看:118
本文介绍了jQuery的/阿贾克斯饼干PT2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从previous问题继,( previous问题),我似乎无法能够火Ajax调用如果检测到的Cookie。该Cookie是绝对设置,并显示警告,但我不能为我的生命得到它再次触发Ajax调用。我只需要它火了Ajax时,如果检测到cookie中的页面加载,而不是使用更多按钮。

Following on from a previous question, ( Previous question), I can't seem to be able to 'fire' the ajax call if a cookie is detected. The cookie is definitely set, and the alert is displayed, but I can't for the life of me get it to trigger the ajax call again. I just need it to 'fire' the ajax when the page is loaded if the cookie is detected, rather than using the 'more' button.

希望这是有道理的。任何帮助非常AP preciated。秒。

Hope this makes sense. Any help greatly appreciated. S.

 $(document).ready(function(){                                                 
        $(function() {
        //More Button                        
        $('.more').live("click",function() 
        {    
        $.cookie('viewing_expanded_content',true, { expires : new Date(new Date().valueOf() + 60 * 60 * 1000) });
        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>');
        //$.cookie('viewing_expanded_content', null);
        }
        return false;
                });

              });

        var viewing_expanded_content = $.cookie('viewing_expanded_content');
        if ( viewing_expanded_content == 'true' ) {

        alert("Active cookies!");    

        //my proposed call that doesnt work
        $.ajax({                   
        type: "POST",
        url: "more_press.php",
        data: "lastmsg="+ ID, 
        cache: false,
        success: function(html){                                        
        $("div#updates").append(html);
        $("#more"+ID).remove();
                }
            });
        }    

        })

编辑:在这里工作的解决方案...

推荐答案

要放一个错误回调功能可按你可以像这样

To put an error callback funciton you can do like this

//my proposed call that doesnt work    

$.ajax({                   
    type: "POST",
    url: "more_press.php",
    data: "lastmsg="+ ID, 
    cache: false,
    success: function(html){                                        
        $("div#updates").append(html);
        $("#more"+ID).remove();
    },
    error: function(){
        // write your code for error handling
    }
});

这篇关于jQuery的/阿贾克斯饼干PT2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆