I have this jQuery AJAX code, when the request is successful, it does this:
success: function(msg)
{
$('.login-msg').css('color', 'green');
$('.login-msg').hide().html(msg).fadeIn('slow');
$('#user-tools').hide().html('<span class="user-credits"><a href="javascript:void(0);" class="logout-btn">Logout</a></span>').fadeIn('slow');
}
However, I can't click on the link with the class logout-btn
which has a jQuery click function which will logout the user, although when I refresh the page, it still has the HTML as this:
<span class="user-credits"><a href="javascript:void(0);" class="logout-btn">Logout</a></span>
But how come I can't click on it to do the click function done here:
$('.logout-btn').click(function(){
$.ajax({
url: 'include/logout.php',
cache: false,
success: function(msg)
{
$('.logout-btn').html('<p><img src="img/loading.gif" style="vertical-align: bottom;" /> Refreshing...</p>');
setTimeout(function()
{
window.location.reload();
}, 1000);
},
error: function()
{
$('.logout-btn').css('color', 'red');
$('.logout-btn').hide().html('Error trying to log out, try again later').fadeIn('slow');
}
});
});
Cheers.