【发布时间】:2016-04-04 10:38:26
【问题描述】:
我在我的网站中使用 Bootstrap v3.3.5。
在一种情况下,我在 Bootstrap 模式对话框中显示一个表单。用户填写数据并提交表单。提交表单后,表单将保持原样,直到收到来自服务器的响应。
所以,我想做的是显示一个蓝色水平进度条,它与 gmail 在登录后加载收件箱邮件列表时使用的蓝色水平进度条完全相似。这个进度条应该像 gmail 的进度条一样是动态的(即本质上是渐进的,而不是像旋转圆加载器图像)。
它应该显示在表单顶部,并带有消息“请稍候...正在生成您的事件。”我在我的代码中添加了一条注释,告诉它应该在哪里准确显示。
以下是我的 Bootstrap modal 的 HTML 代码:
<form method="post" action="{$site_url}add_event.php" id="formAddEvent" >
<!-- The gmail look alike loader should display here only upon successfull submission of a form. -->
<div class="form-group" id="addEventErrorMsg" style="display:none; color:#FF0000;">
</div>
<div class="form-group">
<input type="text" name="txt_event_title" id="txt_event_title" autocomplete="off" class="form-control custom-height" placeholder="Event Title" style="height:30px;" />
</div>
<div class="form-group">
<textarea type="text" name="txt_event_description" id="txt_event_description" autocomplete="off" class="form-control custom-height" placeholder="Description (optional)" style="height:60px;" ></textarea>
</div>
<table border="0" cellspacing="10">
<tr>
<th><span class="event-title1" style="margin-bottom:5px;">Start Date:</span></th>
<th><span class="event-title1" style="margin-bottom:5px;">End Date:</span></th>
</tr>
<tr>
<td>
<div style="margin-right:15px;" class="form-inline form-group event-selection">
<div class="form-group has-feedback">
<div class='input-append date form_datetime' data-date="2013-02-21T15:25:00Z">
<input type='text' id='event_start_date' name="event_start_date" style="width:225px; display:inline; height:30px;" class="form-control" autocomplete="off" />
<span aria-hidden="true" class="glyphicon glyphicon-calendar form-control-feedback"></span>
</div>
</div>
</div>
</td>
<td>
<div class="form-inline form-group event-selection">
<div class="form-group has-feedback">
<div class='input-append date form_datetime' data-date="2013-02-21T15:25:00Z">
<input type='text' id='event_end_date' name="event_end_date" style="width:225px; display:inline;height:30px;" class="form-control" autocomplete="off" />
<span aria-hidden="true" class="glyphicon glyphicon-calendar form-control-feedback"></span>
</div>
</div>
</div>
</td>
</tr>
</table>
<div class="form-group has-feedback">
<input type="text" name="txt_event_location" id="txt_event_location" autocomplete="off" class="controls form-control custom-height" placeholder="Event Location" style="height:30px;" />
<span class="glyphicon glyphicon-map-marker form-control-feedback" aria-hidden="true"></span>
</div>
<div style="clear:both;"> </div>
<div id="map"></div>
<div class="form-group">
<input type="text" name="txt_event_room" id="txt_event_room" autocomplete="off" class="form-control custom-height" placeholder="Room No." style="height:30px;" />
</div>
<div class="form-group">
<div id="custom-templates">
<input class="typeahead form-control custom-height" id="selected_groupname" name="selected_groupname" type="text" placeholder="Invite Group" value="{foreach from=$user_group_list1 item=grouplist key=key} {if $groupId==$grouplist.page_id} {$grouplist.title} {/if} {/foreach}">
<input type="hidden" name="selected_groupid" id="selected_groupid" value="" />
</div>
</div>
<div class="modal-footer text-center">
<button class="btn btn-primary" id="btn_add_event" type="button">Add Event</button>
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
</div>
</form>
点击id为btn_add_event的按钮提交表单时调用的函数如下:
$(document).ready(function() {
$("#btn_add_event").click(function() {
var strSeriaze = $( "#formAddEvent" ).serialize();
url = $( "#formAddEvent" ).attr('action');
$("#btn_add_event").attr('disabled', 'disabled');
$("#addEventErrorMsg").html('');
$.ajax({
url : url,
type : "POST",
data : {postData:strSeriaze},
beforeSend: function() {
$('#loader-icon').show();
},
complete : function() {
$('#loader-icon').hide();
},
success : function(data) {
// $("#events-result").append(data);
$('#loader-icon').hide();
if(data == true) {
$("#myModal-add-event").modal('hide');
$("#myModal-add-event").hide();
//window.location = site_url + "event_index.php";
window.location.href = site_url + "event_index.php";
return false;
} else {
$("#btn_add_event").attr('disabled', false);
$("#addEventErrorMsg").show();
$("#addEventErrorMsg").html(data);
}
},
error: function() {}
});
})
});
请帮助我。谢谢。
我的问题与其他任何问题都不同。我不知道如何处理进度条百分比或响应时间的进度。我没有从任何地方得到解决方案。请从我的问题中删除重复的标签。
【问题讨论】:
-
您可以使用规范xhr.spec.whatwg.org/#interface-progressevent 中的事件,另一种方法是将响应从服务器回显到客户端并根据响应更新进度...所以假设您有一个 switch 语句和 5 个案例 (0-5),您回显 0,它代表服务器上的阶段 1,然后您回显 1,这是下一个阶段,因此您更改进度条的值。
-
@Tasos:我想显示与 gmail 的蓝色进度条完全相似的蓝色进度条。它的必要代码应该适合我给出的代码。您提供的问题链接与我想要实现的完全不同。
-
@JordanDavis:感谢您的评论。如果您可以对我在问题中发布的代码进行必要的更改,请将其发布为答案,如果可能的话,可以创建一个对我有很大帮助的工作演示。再次感谢。
-
我也想说,你做会员这么久,应该知道你问的不是SO做的,所以我觉得很奇怪你还在做。我真的希望你改变这个问题的要求,而不是要求一个完全工作的代码,因为在这里我们花费了大量的个人时间来帮助解决问题,而不是为某人做工作。
标签: javascript jquery ajax twitter-bootstrap loader