This is my markup:
<a href="#" class="reviews" id="like" rel="popover" data-content="" data-placement="right" data-original-title="Like episode">
<i class="icon-thumbs-up"></i>
Loved it
</a>(<span id="episode_likes">{{ episode_likes }}</span>
And this is the JavaScript:
$('a.reviews#like').click(function(e){
var element = $(this);
$.ajax({
url: '/episoderatings/like/',
type: 'POST',
dataType: 'json',
data: {
csrfmiddlewaretoken: '{{ csrf_token }}',
episode_number: current,
story: current_story
},
success: function(response){
if(response=='You have liked this episode'){
$('span#episode_likes').text(parseInt($('span#episode_likes').text())+1);
}
$(element).attr('data-content',response);
$(element).popover();
}
});
e.preventDefault();
});
The problem is when I click on 'like' button, the popover doesn't show up on the first click so I miss the important response whether I've liked the page or not. When I click on the 'like' button, the second time popover shows up and it then maintains its toggle behaviour from there onwards. Any ideas?