1、需求:
在ajax发起请求前弹出一个确认框,用户点击确认再向服务器发送ajax请求
$(document).on('click', '.test', function () {
var url = $(this).data('url');
window.top.layer.confirm('您确定访问服务器吗?', function () {
$.ajax({
url: url,
type: 'GET',
dataType: 'JSON',
loading: true,
beforeSend: function () {
window.top.layer.msg("正在加载请稍后...");
},
success: function (res) {
if (res.success) {
window.top.layer.alert(res.msg);
window.location.reload();
} else {
window.top.layer.alert(res.msg);
}
},
});
})
})