layui实现点击前台一个按钮删除数据库对应表中的记录不是在layui表格中删除

听起来比前一篇简单,其实不然啊!因为不懂js的语法踩了好多的坑呢!

先来看效果吧:下面的表格内容和这次删除无关,那是别的按钮的查询展示效果,只是公用了一个页面而已

layui实现点击前台一个按钮删除数据库对应表中的记录不是在layui表格中删除_第1张图片

废话不多说,先上前端的主要代码:

 
function delAll(){ layui.use(['layer'],function(){ var form=layui.form ,layer=layui.layer ,$=layui.$; layer.confirm('确定删除吗?', {btn: ['确定删除', '取消']}, function (index) { layer.close(index); $.ajax({ url: "/tools/del_looploan", type: "POST", data:{"phone":$('#phone').val(),"crfuid":$('#crfuid').val(),"env_tools":parent.window.env_tools}, //"phone":$('#phone').val()取到input的值传给后台作为删除的条件 dataType: "json", success: function(data){ if(data['status']=="success"){ layer.alert("删除成功",{icon:6}); } else{ layer.alert("删除失败",{icon:5}); } } }); }); }); }

后台Python代码如下:

@toolsbp.route('/del_looploan', methods=['GET', 'POST'])
def del_looploan():
    if request.method =='POST':
        data = {}
        data['data'] = ''
        data['code'] = 0
        data['msg'] = '查询成功'
        data['status']=''
        env = request.form.get('env_tools')
        if env is None:
             return json.dumps(data)  #返回data的内容,将一个Python数据结构转换为JSON

        phone = request.form.get('phone')
        crfuid = request.form.get('crfuid')
        print(phone)
        print(crfuid)

        if phone:
            if crfuid=='':
                dbinfo = env_config.ENV_LIST.get(env.upper()).get('crf_rcs_agent_db')
                dbtool = MysqlPool.MysqlPool(dbinfo.get('db_name'))
                result=dbtool.getAll("select crf_uid from app_db_uat.ct_user where phone= '%(phone)s';"%{'phone':phone})
                print(result)
                print(result[0]['crf_uid'])
                crfuid=result[0]['crf_uid']
        if crfuid:
            if env in ['UAT','UATA']:
                dbinfo = env_config.ENV_LIST.get(env.upper()).get('crf_rcs_agent_db')
                dbtool = MysqlPool.MysqlPool(dbinfo.get('db_name'))
                del_loan01=dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_limit_flow  where crf_uid='%(crfuid)s';"%{'crfuid':crfuid})
                del_loan02 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_limit_flow_detail  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan03 = dbtool.getAll( "delete from crf_rcs_agent_db_uat.agt_loan_agreement  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan04 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_loan_agreement_detail  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan05 = dbtool.getAll( "delete from crf_rcs_agent_db_uat.agt_loan_app  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan06 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_loan_order  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan07= dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_loan_price  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan08 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_loan_times  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan09 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_offline_order  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan10 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_pay_flow  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan11 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_repay_flow  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan12 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_repay_flow_detail  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan13 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_repay_order_detail  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan14 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_repay_offset_detail  where crf_uid='%(crfuid)s';" % { 'crfuid': crfuid})
                del_loan15 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_repay_order  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan16 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_repay_plan  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan17 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_sms_sendlog  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan18 = dbtool.getAll("delete from crf_rcs_agent_db_uat.agt_trxn_log  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan19 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_account  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan20 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_loan_info  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan21= dbtool.getAll("delete from crf_rcs_core_db_uat.act_loan_price  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan22 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_overdue  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan23 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_overdue_detail  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan24 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_overdue_loaninfo  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan25 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_post_pay  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan26 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_post_repay  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan27 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_repay_offset  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan28 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_repay_plan  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan29 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_blacklist  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                del_loan29 = dbtool.getAll("delete from crf_rcs_core_db_uat.act_repay_fee_record  where crf_uid='%(crfuid)s';" % {'crfuid': crfuid})
                data['status'] = "success"
        else:
            "请输入手机号或者crfuid"
        return json.dumps(data, cls=MysqlPool.DateEncoder)
    return render_template('tools/index.html')

在这个过程中因为把ajax的url写成

url: "/tools/del_looploan/"这样,报找不到页面,正确写法:url: "/tools/del_looploan"

你可能感兴趣的:(python学习)