<html> <head> <title></title> <meta charset="UTF-8" /> <script src="jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script> </head> <body> <form name="form1" id="form1" enctype="multipart/form-data"> <input type="file" name="img" id="img" value="" onchange="dj()" /> </form> <script type="text/javascript"> function dj() { var form = document.getElementById(‘form1‘); var oMyForm = new FormData(); oMyForm.append("username", "Groucho"); oMyForm.append("sex", "Groucho"); oMyForm.append(‘img‘, $(‘#img‘)[0].files[0]); $.ajax({ url: "http://192.168.1.105/ifangApi/?s=Api/Order/aa", type: "POST", data: oMyForm, processData: false, // 告诉jQuery不要去处理发送的数据 contentType: false // 告诉jQuery不要去设置Content-Type请求头 }); } </script> </body> </html>
时间: 2024-11-10 07:50:34