首先加入下面的插件,可到https://download.csdn.net/download/qq_38522268/10689121和https://download.csdn.net/download/qq_38522268/10689045下载
<script th:src="@{/js/jquery-1.8.0.min.js}" type="text/javascript"></script>
<link th:href="@{/css/showLoading.css}" rel="stylesheet" type="text/css"/>
<script type="text/javascript" th:src="@{/js/jquery.showLoading.min.js}"></script>
然后在ajax里使用loading
<script th:inline="javascript">
/*<![CDATA[*/
$(document).ready(function () {
var mac = [[${mac}]];
var first = [[${first}]];
var last = [[${last}]];
$("html").showLoading();//此处加载loading
$.ajax({
type: "POST",
url: "",//url
dataType: "json",
data: {//data就是参数,是json格式
mac: mac,
firstdate: first,
lastdate: last
},
success: function (data) {
$("html").hideLoading();//此处隐藏loading
} else if (data.code === 403) {
alert(data.describe);
}
},
error: function () {
alert('哎呀!出错了!');
}
});
});
/*]]>*/
</script>