| | |
| | | return JSON.stringify(model); |
| | | } |
| | | |
| | | function UploadImg() { |
| | | var formData = new FormData(); |
| | | var fs = document.getElementById("imgs"); |
| | | for (var i = 0, c = fs.files.length; i < c; i++) { |
| | | formData.append(fs.files[i].name, fs.files[i]); // name, file |
| | | } |
| | | |
| | | $.ajax("Img/Upload", { |
| | | type: "POST", |
| | | data: formData, |
| | | async: true, |
| | | cache: false, |
| | | processData: false, |
| | | contentType: false, |
| | | success: function (rs) { |
| | | console.log(rs); |
| | | alert(JSON.stringify(rs)); |
| | | }, |
| | | error: function (e) { |
| | | console.error(e); |
| | | alert("上传文件失败!"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | function ajax(url, type, data, dataType, contentType, fn) { |
| | | $.ajax({ |
| | | url: url, |
| | |
| | | |
| | | id: <input id="iid" value="1" /> <br /> |
| | | name: <input id="iname" value="1.jpg"/> <br /> |
| | | path: <input id="ipath" value="Images\1.jpg"/> <br /> |
| | | path: <input id="ipath" value="Images/1.jpg"/> <br /> |
| | | json: <input id="ijson" value="{}"/> <br /> |
| | | <input type="button" value="InsertImg" onclick="InsertImg();" /> |
| | | <input type="button" value="UpdateImgById" onclick="UpdateImgById();" /><br /> <br /> |
| | | <input type="button" value="UpdateImgById" onclick="UpdateImgById();" /> |
| | | <label for="apifiles">选择图片:</label> |
| | | <input id="imgs" type="file" multiple="multiple" accept=".jpg,.png" /> |
| | | <input value="UploadImg" type="button" onclick="UploadImg();" /> |
| | | <br /> <br /> |
| | | </form> |
| | | </body> |
| | | </html> |