SpringMVC + ajaxFileUpload solution for uploading images to IE browser via pop-up download box
For example, record the solution to this problem. The core cause is that ajaxfileupload does not support setting the Response Header ContentType to application/json, and IE does not support this format, when SpringMVC's @ ResponseBody annotation is used, the response type is automatically set to application/json, so the solution is to manually set the response type.
Step 1 discard @ ResponseBody, manually output the response through the stream, and specify the response type as text/html
@ RequestMapping (value = "/fileImport2") public Map
FileImport2 (HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest req, @ RequestParam ("filename") MultipartFile uploadFile) {response. setContentType ("text/html; charset = UTF-8"); try {// File Upload String updateLoadPath = FileOperateUtil. uploadExcel (req, request, uploadFile); String publishPath = request. getSession (). getServletContext (). getRealPath ("/");//... response. getWriter (). write ("{\" data \ ": \" OK \ "}");} catch (Exception e) {e. printStackTrace (); try {response. getWriter (). write ("{\" data \ ": \" error \ "}");} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace ();}} return null ;}
Step 2 set dataType of $. ajaxFileUpload to text (otherwise, the value of the callback function is [object. object])
$. AjaxFileUpload ({url: postPath + "/app/studentScore/fileImport2", // secureuri: false, // whether the security protocol is required, generally set to false fileElementId: 'filename', // The ID dataType: 'text' of the file upload field, // the return value type is generally set to json success: function (data) // The server responds to the processing function {alert (data); var repObj = $. parseJSON (data); if (repObj. data = 'OK') {alert ("imported successfully! ");} Else {alert (" Data Exception! ");}}});
After the problem is solved, let's take a brief look at the debugging information of FireBug: