经常用,又经常记不住,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>
上一篇: 《建站管家》二次开发文档