ajax结合bootstrap4提交表单

南国老符 南国老符 最后更新于:2019-12-10 浏览:2723

经常用,又经常记不住,mark一下,以后直接抄:

<button onClick='operation("#form_list","#update_all","{:url('/ad/update_all',['lang'=>input('lang')])}");'>提交</button>

function operation(form_id,btn_id,url){
    $.ajax({
        type: 'POST',
        url: url,
        dataType: 'json',
        data: $(form_id).serialize(),
        //发送数据前
        beforeSend: function(){
            // 禁用按钮防止重复提交
            $(btn_id).attr({disabled: "disabled"});
            //弹出modal框
            $('#modal_sm_black_content').html('<img src="loading-white.gif" width="18" height="18" class="mr-2">正在处理,请稍后');
            $("#modal_sm_black").modal("show");
        },
        //成功返回
        success: function(data){
            setTimeout(function(){
                //隐藏modal框
                $(btn_id).removeAttr('disabled');
                $('#modal_sm_black').modal('hide');
                switch(data){
                    case 'success':
                        //操作成功,弹出modal框
                        $('#modal_sm_black_content').html('<i class="fas fa-check-circle mr-2"></i>操作成功');
                        $("#modal_sm_black").modal("show");
                        window.location.reload();
                        break;
                }
            }, 1);
        },
        //处理完成
        complete: function(){
            $(btn_id).removeAttr('disabled');
            $('#modal_sm_black').modal('hide');
        },
        //报错
        error: function(data){
            console.info("error: " + data.responseText);
        }
    });
}
modal框:
<div class="modal" id="modal_sm_black" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content bg-opacity">
            <div class="modal-body py-3 text-white text-center text-md" id="modal_sm_black_content"></div>
        </div>
    </div>
</div>



点赞 (0)

收藏 (0)
转载请务必注明: 来源:《建站管家》https://www.df81.com/news/37.html

本站部分信息来源网络,如有侵权,请联系QQ:1062129401删除。

上一篇: thinkphp5.1.x升级到tp6.0笔记(二)

下一篇: thinkphp缓存文件写入失败及403 Forbidden的解决方法

请先登录后,再发表评论 ~ ~
发表评论
评论 (0)

发表帖子
广告位招租( ¥5 / 天 )
点击咨询
最新帖子

南国老符
2025-05-26 16:54
南国老符
2024-09-29 10:29
南国老符
2023-12-15 21:41
广告位招租( ¥5 / 天 )
点击咨询
最近评论

U
user1379
回复:版本号多少?
U
user1379
回复:新版本修复了,下载新版本即可
U
user1379
U
user1304
回复:默认没有这个功能,你可以自行二次开发后期可能会考虑在站群版本上加入此功能及商城功能
Y
yuanis90
回复:后台->语言->全局管理->模型管理->编辑->启用关键词内链即可
Y
yuanis90
回复:后台已经启用了,但是前台产品说明的关分键词还是没有自动链接到,
购买VIP
购买授权
余额充值
发表帖子
客服微信