开发者

Jquery/Ajax cookie pt2

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.

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({                   
开发者_如何学JAVA        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();
                }
            });
        }    

        })

EDIT: Working solution here...


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
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜