• 使用layer的iframe层提交表单后,需要关闭当前的iframe层,然后刷新父页面的方法2


    <input type="button" onclick="edit(${it.id?c})"
    class="layui-btn layui-btn-normal layui-btn-sm" value="编辑">
      function edit(id) {
    //iframe层
    layer.open({
    type: 2,
    title: '编辑服务商',
    shadeClose: true,
    shade: 0.8,
    area: ['650px', '550px'],
    content: '/serprovider/getSerproviderById?id=' + id //iframe的url
    });
    }

    @RequestMapping(value = "/getSerproviderById", method = RequestMethod.GET)
    public ModelAndView getSerproviderById(@RequestParam(value = "id", required = true) Integer id) {
    ModelAndView modelAndView = new ModelAndView();
    ServiceProvider serviceProvider = serviceProviderService.getSerproviderById(id);
    modelAndView.addObject("info", serviceProvider);
    modelAndView.setViewName("serprovider/getSerproviderById");
    return modelAndView;

    }


    <!-- 内容主体区域 -->
    <form class="layui-form" action="#" method="post">
    <div class="layui-form-item">
    <label class="layui-form-label">供应商名称<span style="color: red;">*</span></label>
    <div class="layui-input-block">
    <input type="text" name="providerName" required lay-verify="required" placeholder="请输入供应商名称"
    value="${info.providerName!}"
    autocomplete="off" class="layui-input">
    </div>
    </div>
    <div class="layui-form-item">
    <label class="layui-form-label">公司名称<span style="color: red;">*</span></label>
    <div class="layui-input-block">
    <input type="text" name="providerCompany" required lay-verify="required"
    value="${info.providerCompany!}"
    placeholder="请输入公司名称"
    autocomplete="off" class="layui-input">
    </div>
    </div>
    <div class="layui-form-item">
    <label class="layui-form-label">联系人<span style="color: red;">*</span></label>
    <div class="layui-input-block">
    <input type="text" name="linkMan" required lay-verify="required" placeholder="请输入联系人"
    value="${info.linkMan!}"
    autocomplete="off" class="layui-input">
    </div>
    </div>
    <div class="layui-form-item">
    <label class="layui-form-label">联系电话<span style="color: red;">*</span></label>
    <div class="layui-input-block">
    <input type="text" name="cellphone" required lay-verify="required|number" placeholder="请输入联系电话"
    value="${info.cellphone!}"
    autocomplete="off" class="layui-input">
    </div>
    </div>

    <div class="layui-form-item">
    <div class="layui-input-block">
    <input type="hidden" name="id" value="${info.id?c}">
    <button lay-submit lay-filter="go"
    class="layui-btn layui-btn-normal ">提交
    </button>
    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
    </div>
    </form>
    <script>
    layui.use('element', function () {
    var element = layui.element;
    });
    layui.use('form', function () {
    var form = layui.form;
    // 这个是在iframe里面的js代码
    var frameindex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    form.on('submit(go)', function (data) {
    console.log(data.field); //当前容器的全部表单字段,名值对形式:{name: value}
    var index = layer.load(1, {
    shade: [0.1, '#fff'] //0.1透明度的白色背景
    });
    var url = '/serprovider/saveEditServiceProvider';
    $.post(url, data.field, function (ev) {
    if (ev.code == 200) {
    layer.msg(ev.msg);
    parent.location.href = "/serprovider/getServiceProviderList";
    } else {
    layer.close(index);
    layer.msg(ev.msg);
    }
    }, 'json')
    //发送ajax
    return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
    });
    });
    </script>

    @RequestMapping(value = "/saveEditServiceProvider", method = RequestMethod.POST)
    @ResponseBody
    public Map saveEditServiceProvider(ServiceProvider serviceProvider) {
    boolean flag = serviceProviderService.saveEditServiceProvider(serviceProvider);
    Map map = new HashMap();
    if (flag) {
    map.put("code", 200);
    map.put("msg", "更改成功");
    } else {
    map.put("code", "500");
    map.put("msg", "更改失败,代码错误");
    }
    return map;
    }
  • 相关阅读:
    C++---继承和派生
    【解迷糊】关于PHP的extract()函数提取出的变量的作用域问题
    PHP常用内置函数记忆(持更)
    PHP数据类型转换
    在window把自己的项目上传到github
    github Desktop上传项目
    【终于明白】PHP加入命名空间的好处--方便自动加载
    PHP中session的使用方法和生命周期问题
    php
    PHP中include和require的区别详解
  • 原文地址:https://www.cnblogs.com/jwlfpzj/p/9216898.html
Copyright © 2020-2023  润新知