HTML
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>loading加载 - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="http://lyear.itshubao.com/iframe/css/bootstrap.min.css" rel="stylesheet">
<link href="http://example.itshubao.com/demo/css/materialdesignicons.min.css" rel="stylesheet">
<link href="http://lyear.itshubao.com/iframe/v4/css/animate.min.css" rel="stylesheet">
<link href="http://lyear.itshubao.com/iframe/css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="form-group">
<button type="submit" class="btn btn-primary" id="example-one">确认提交</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/jquery.min.js"></script>
<script type="text/javascript" src="http://libs.itshubao.com//jquery.lyear.loading.js"></script>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/v4/js/bootstrap-notify.min.js"></script>
</body>
</html>
JavaScript
function ajaxPostFun(selfObj, ajax_url, form_data, loader) {
jQuery.post(ajax_url, form_data).done(function(res) {
selfObj.find('.lyear-loading').remove(); // 清除按钮上的loading
loader.destroy();
var res = eval('(' + res + ')');
var msg = res.msg;
if (200 == res.code) {
if (res.url && !selfObj.hasClass('no-refresh')) {
msg += '页面即将自动跳转';
}
//showNotify(msg, 'info');
setTimeout(function () {
selfObj.attr("autocomplete", "on").prop("disabled", false);
return selfObj.hasClass("no-refresh") ? false : (res.url ? location.href = res.url : location.reload());
}, 1500);
} else {
//showNotify(msg, 'danger');
selfObj.attr("autocomplete", "on").prop("disabled", false);
}
}).fail(function () {
loader.destroy();
selfObj.find('.lyear-loading').remove(); // 清除按钮上的loading
showNotify('服务器发生错误,请稍后再试', 'danger');
selfObj.attr("autocomplete", "on").prop("disabled", false);
});
}
/*
* 提取通用的通知消息方法
* 这里只采用简单的用法,如果想要使用回调或者更多的用法,请查看lyear_js_notify.html页面
* @param $msg 提示信息
* @param $type 提示类型:'info', 'success', 'warning', 'danger'
* @param $delay 毫秒数,例如:1000
* @param $icon 图标,例如:'fa fa-user' 或 'glyphicon glyphicon-warning-sign'
* @param $from 'top' 或 'bottom' 消息出现的位置
* @param $align 'left', 'right', 'center' 消息出现的位置
*/
function showNotify($msg, $type, $delay, $icon, $from, $align) {
$type = $type || 'info';
$delay = $delay || 1000;
$from = $from || 'top';
$align = $align || 'right';
$enter = $type == 'danger' ? 'animated shake' : 'animated fadeInUp';
jQuery.notify({
icon: $icon,
message: $msg
},
{
element: 'body',
type: $type,
allow_dismiss: true,
newest_on_top: true,
showProgressbar: false,
placement: {
from: $from,
align: $align
},
offset: 20,
spacing: 10,
z_index: 10800,
delay: $delay,
animate: {
enter: $enter,
exit: 'animated fadeOutDown'
}
});
}
$(document).ready(function(){
// 按钮中的loading
$('#example-one').click(function(){
var l = $(this).lyearloading({
opacity: 0.2,
spinnerSize: 'nm'
}); // 按钮上的loading
var loader = $('body').lyearloading({
opacity: 0.2,
spinnerSize: 'lg'
}); // body上的loading
ajaxPostFun($(this), "http://www.fdsafd.com/fdsafd", "fdsafdsa", loader);
});
});