(ajax)query中全局事件ajaxStart ajaxStop
Jquery中当一个Ajax请求启动时,并且没有其他未完成的Ajax请求时,
将调用ajaxStart()方法。
同样,ajaxStop()方法则是在所有Ajax请求都完成时调用。
这些方法的参数都是一个函数,
这个函数将在事件发生时被调用。
jquery1.9+版本以后,ajax全局事件需绑定到document对象上才能触发。
<link rel="stylesheet" href="./nprogress.css">
<style>
.loading{
display:none;
position:fixed;
background: rgba(0,0,0,.3);
text-align:center;
top:0;
bottom:0;
left:0;
right:0;
color:#fff;
font-size: 60px;
};
</style></head>
<body>
<div class="loading">正在玩命加载中...</div>
<button id="btn">请求</button>
<script src="./jquery.js"></script>
<script src="./nprogress.js"></script>
<script>
$(document)
.ajaxStart(function(){
//只要有ajx请求发生 就会执行
$('.loading').fadeIn()
NProgress.start();
// 显示加载提示
console.log('注意即将开始请求了')
})
.ajaxStop(function(){
$('.loading').fadeOut()
NProgress.done();
// 结束提示
console.log("请求结束了")
})
$('#btn').on('click',function(){
$.get('time.php')
})
</script> 相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
时光如瑾雨微凉 2020-07-19
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05