tags:

views:

30

answers:

1

Hi,

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({                   
        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...

A: 

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
    }
});
rahul
Many thanks. Unfortunately no error was returned, (Added an alert).
ss888