我有以下Ajax请求,该请求位于部分视图中,该视图从服务请求地址,并且可能需要几秒钟来填充表:
@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "updatearea", OnBegin = "ShowLoading", OnComplete = "HideLoading" }))
{
<div id="updatearea" class="form-group">
<div style="width:300px; display:block; float:left;">
@Html.TextBox("PostCode", null, new { @class = "form-control" })
</div>
<div id="NewAddressLine">
<input id="btnLookupPostcode" type="submit" value="Lookup Postcode" class="btn btn-default" />
</div>
</div>
<div id="spinner"></div>
}
这个JavaScript已成功启动了加载微调器,但在部分视图完全呈现后就不会停止它:
function ShowLoading() {
var opts = {
lines: 13, // The number of lines to draw
length: 20, // The length of each line
width: 10, // The line thickness
radius: 30, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#000', // #rgb or #rrggbb or array of colors
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: '50%', // Top position relative to parent
left: '50%' // Left position relative to parent
};
var target = document.getElementById('spinner');
var spinner = new Spinner(opts).spin(target);
}
function HideLoading() {
var spinner = $('.spinner');
spinner.stop();
}
请停止!
最初以评论形式发布,并且有一些根本性的解决方案,但这将完全阻止它:
spinner.remove()
清理所有引用和附加事件...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句