I'm practicing with twitter bootsrap and made an example website. I use modal view to display warnings when users vote. But it won't display the warning when you vote first time. it displays second time. if you go to my test site and click on up arrow you will see nothing will be displayed. but when you click one more time you will see the modal message.(which is saying you have to be logging to vote in my language) I cannot figure out why it's happening. thanks for your help.
this is my jquery.
<script>
jQuery(document).ready(function($){
$('.upvote').click( function(event) {
event.preventDefault();
var voteID = $(this).attr("id");
$.ajax({
url: "/ajax.php?Page=votetitle",
type: "post",
dataType: "json",
data: {id : voteID, vote: '1'},
success: function(data){
if(data.success == 'true'){
$('#voteresponse'+voteID).html(data.message);
}else{
$(".upvote").attr("data-toggle", "modal");
$(".upvote").attr("data-target", "#modal");
$('#modal').modal('show');
$('#modal').on('show', function () {
$('.ModalLabel',this).html('Oy verirken hata oluştu!').css({color: 'red'});;
$('.modal-body',this).html(data.message);
});
}
},
error:function(){
$('#voteresponse').popover({
title: 'Hata!',
content: 'Server hatasi'
});
}
});
});
$('.downvote').click( function(event) {
event.preventDefault();
var voteID = $(this).attr("id");
$.ajax({
url: "/ajax.php?Page=votetitle",
type: "post",
dataType: "json",
data: {id : voteID, vote: '2'},
success: function(data){
if(data.success == 'true'){
$('#voteresponse'+voteID).html(data.message);
}else{
$(".downvote").attr("data-toggle", "modal");
$(".downvote").attr("data-target", "#modal");
$('#modal').modal('show');
$('#modal').on('show', function () {
$('.ModalLabel',this).html('Oy verirken hata oluştu!').css({color: 'red'});;
$('.modal-body',this).html(data.message);
});
}
},
error:function(){
$('#voteresponse').popover({
title: 'Hata!',
content: 'Server hatasi'
});
}
});
});
});
</script>
modal html
<div id="modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="ModalLabel"></h3>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Kapat</button>
</div>
</div>
and buttons
<button type="submit" class="btn btn-mini upvote" id="'.$data['ContentID'].'"><i class="icon-arrow-up"></i></button>
<span id="voteresponse'.$data['ContentID'].'">'.intval( $data['TotalVotes'] - $data['VoteSum'] ).'</span>
<button type="submit" class="btn btn-mini downvote" id="'.$data['ContentID'].'"><i class="icon-arrow-down"></i></button>