Hi,
How would I make an ajax call if a page detects a cookie is present? The code below fires the alert but not the ajax call. Any help greatly appreciated.
EDIT: Updated and fully working code below. Simply had to change $(this) to $('.more') when the cookie is found. Many thanks for help/advice.
$(document).ready(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: true,
success: function(html){
$("div#updates").append(html);
$("#more"+ID).remove();
}
});
} else {
$(".morebox").html('<p><strong>No more results...</strong></p>');
}
return false;
});
var viewing_expanded_content = $.cookie('viewing_expanded_content');
if ( viewing_expanded_content == 'true' ) {
//alert("Active cookies!");
var ID = $('.more').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: true,
success: function(html){
$("div#updates").append(html);
$("#more"+ID).remove();
}
});
}
}
})