ajax结合bootstrap4提交表单

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

经常用,又经常记不住,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的解决方法

请先登录后,再发表评论 ~ ~
发表评论
发表帖子
广告位招租( ¥5 / 天 )
点击咨询
最新帖子

南国老符
2025-07-14 00:59
南国老符
2025-07-13 19:36
南国老符
2025-05-26 16:54
南国老符
2024-09-29 10:29
广告位招租( ¥5 / 天 )
点击咨询
最近评论

Y
yuanis90
回复:在后台->全局管理->网站设置->网站html代码,把你申请的分享代码贴到这里保存即可。以后发问题,请贴出具体版本号
南国老符
回复:发表帖子发不了  乱码
南国老符
回复:第一位参与的老总,是做洗衣店saas系统的,需要的请联系
9
9252
回复:新版已经修复了的,升级忘记覆盖了,你重新下载即可。
U
user1304
回复:PHP开启fileinfo扩展即可
U
user1379
回复:版本号多少?
购买VIP
购买授权
余额充值
发表帖子
客服微信