html:

<form class="layui-form" action="" lay-filter="form-group">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">xxx</label>
            <div class="layui-input-inline">
              <input type="xxx" name="xxx"  class="layui-input">
            </div>
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">xxxx</label>
          <div class="layui-input-block">
            <input type="radio" name="111" value="111" title="111" checked="">
            <input type="radio" name="222" value="222" title="222">
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="form-submit">提交</button>
          </div>
        </div>
      </form>



js:


<script>
form.on('submit(form-submit)', function (inputData) {
        console.log("inputData:",inputData);
        $.ajax({
            url:"xxxxx",
            data:{'xxx':xxx,'xx':xxx},
            type:"post",
            dataType:"json",
        headers : {'Content-Type' : 'application/json;charset=utf-8'}, //接口json格式
            success:function(data){
                console.log(data);
                layer.alert(JSON.stringify(data), {
                    title: data
                });
            },
            error:function(data){
                layer.alert(JSON.stringify(data), {
                    title: data
                });
            }
        });
</script>

get:

将post方式改成get方式,url改成对应的地址即可

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐