企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 12.14.表单提交带文件上传 ```html <form class="layui-form" id="demoForm"> <input type="file" name="file" class="layui-input"/> <input type="text" name="title" class="layui-input"/> <button class="layui-btn" lay-filter="demoSubmit" lay-sunmit>提交</button> </form> <script> form.on('submit(demoSubmit)', function (data) { var formData = new FormData(); for(var f in data.field) { if(!data.field.hasOwnProperty(f)) continue; formData.append(f, data.field[f]); } $('#demoForm [type="file"]').each(function() { formData.append($(this).attr('name'), $(this)[0].files[0]); }); $.ajax({ url:'/url', type:'post', processData:false, contentType:false, data:formData, success:function (res) { console.log(res); } }); return false; }); </script> ``` <br/>