ajax结合bootstrap4提交表单

知识技术 2019-12-10 11:40 2521
转载请务必注明: 来源:《建站管家》https://www.df81.com/news/37.html

经常用,又经常记不住,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)

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

上一篇: 《建站管家》二次开发文档

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

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

如果要判断文件是否存在,用函数 is_file(),如果要判断目录是否存在,用函数 is_dir()
用宝塔安装TP程序后,网站前台可以访问,后台无法访问,不是程序问题,而是web服务器环境配置问题(PHP配置),出现这种问题,一般是windows主机安装宝塔造成的,linux安装宝塔不会出现此错误
广告位招租( ¥3 / 天 )
点击咨询
广告位招租( ¥2 / 天 )
点击咨询
广告位招租( ¥1 / 天 )
点击咨询
最新帖子

小朋友,你爸爸是谁啊?这很单纯的,就像我们碰到别人会问:你吃过饭了吗?类似;许多人初次相识,经常会问:你是做什么的啊?你做什么,好像决定你收入的高低,你,资产的范围
1、升级框架到ThinkPHP8.0.3【要求PHP8.1+环境,推荐PHP8.1】 2、启用/禁用调试模式等小细节改进
后台点击生成站点地图 一直转圈圈没有反应,
在线客服