前端:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 <title></title> 6 </head> 7 <body> 8 <input type="file" id="myphoto" /> 9 <div style="display:none" id="div_div1"> 10 <img src="#" id="img_myphoto" /> 11 </div> 12 </body> 13 </html> 14 <script src="assets/js/jquery-1.7.1.js"></script> 15 <script type="text/javascript"> 16 $("#myphoto").change(function () { 17 var file = this.files[0]; 18 var formData = new FormData(); 19 formData.append('tFile', file); 20 jQuery.support.cors = true; 21 $.ajax({ 22 type: "POST", // 必须用post 23 url: "http://118.200.100.100:8080/uploadStudentIDCard.ashx?studentID=100", 24 crossDomain: true, 25 data: formData, 26 contentType: false, 27 processData: false, 28 success: function (data) { 29 if (data.result == 1) { 30 $("#img_myphoto").attr("src", "http://114.215.198.241:8086" + data.url); 31 $("#div_div1").show(); 32 } 33 }, 34 error: function (res) { 35 alert('shit'); 36 } 37 }); 38 }); 39 </script>