JQuery BlockUI插件和Angular:将ajax调用时间显示为递增的秒数,以代替微调器图像
我试图显示ajax调用的执行时间,而不是标准的ajax微调器。我正在使用JQuery的BlockUI插件。我考虑过做以下几点:JQuery BlockUI插件和Angular:将ajax调用时间显示为递增的秒数,以代替微调器图像,jquery,ajax,angularjs,jquery-blockui,Jquery,Ajax,Angularjs,Jquery Blockui,我试图显示ajax调用的执行时间,而不是标准的ajax微调器。我正在使用JQuery的BlockUI插件。我考虑过做以下几点: $.blockUI.defaults = { // message displayed when blocking (use null for no message) message: $scope.runningTime, 然后在某个地方 $(document).ajaxStart($.blockUI); // add code to incre
$.blockUI.defaults = {
// message displayed when blocking (use null for no message)
message: $scope.runningTime,
然后在某个地方
$(document).ajaxStart($.blockUI); // add code to increment $scope.runningTime
//and do $scope.$apply();
我愿意接受其他建议。最终得出以下解决方案:
<div id="runningTime" style="display:none">
{[{runningTime}]} seconds
</div>
<script src="{{ url_for('static', filename='js/jquery.blockUI.js') }}"></script>
<script>
$(function(){
var $scope = angular.element($("body")).scope();
$scope.start_time = new Date().getTime();
$scope.intervalFn = null;
$(document).ajaxStart(function(){
$.blockUI({ message: $("#runningTime") });
$scope.intervalFn = setInterval(function(){
var ms = new Date().getTime() - $scope.start_time;
$scope.runningTime = (ms/1000) % 60;
try {
$scope.$apply();
} catch(err) {
//do-nothing for now
}
},1000);
});
$(document).ajaxStop(function(){
$.unblockUI();
clearInterval($scope.intervalFn);
});
});
</script>
{[{runningTime}]}秒
$(函数(){
var$scope=angular.element($(“body”).scope();
$scope.start_time=new Date().getTime();
$scope.intervalFn=null;
$(文档).ajaxStart(函数(){
$.blockUI({消息:$(“#运行时”)});
$scope.intervalFn=setInterval(函数(){
var ms=new Date().getTime()-$scope.start\u time;
$scope.runningTime=(ms/1000)%60;
试一试{
$scope.$apply();
}捕捉(错误){
//现在什么都不要做
}
},1000);
});
$(文档).ajaxStop(函数(){
$.unbui();
clearInterval($scope.intervalFn);
});
});