【发布时间】:2013-04-27 21:59:29
【问题描述】:
我正在练习 twitter bootsrap 并制作了一个示例网站。我使用模态视图在用户投票时显示警告。但是当您第一次投票时它不会显示警告。它显示第二次。如果您转到my test site 并单击向上箭头,您将看到不会显示任何内容。但是当您再单击一次时,您会看到模态消息。(这就是说您必须登录才能用我的语言投票)我无法弄清楚为什么会发生这种情况。感谢您的帮助。
这是我的 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>
模态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>
和按钮
<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>
【问题讨论】:
标签: jquery html ajax twitter-bootstrap