ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 表单提交带文件上传 ## 12.14.表单提交带文件上传 ~~~ <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> ~~~