ExtJS File Download Response?

I am trying to check the contents of some files via the web interface and use the answer to enable / disable some other functions ... for example, the save button. I got to sending and processing files (cut through), but I can not get my answer to work correctly.

Problem: When responding, it tries to force the user to upload a file with the contents of the response. I just want to convey the response to the success function that needs to be processed.

JS function code:

function validateCopybook() { //submit values. console.log("validating"); if (this.getForm().isValid()) { this.getForm().submit({ url : 'batch/validateCopybook.json', waitMsg : 'Validating...', success : function(form, action) { this.msg('Success', 'Processed file on the server'); } }); } } 

Server Side Code:

 public ModelAndView validateCopybook(HttpServletRequest request, HttpServletResponse response) throws Exception { // Check whether we're dealing with a multipart request String contentHeader = request.getHeader("content-type"); boolean isMultipart = (contentHeader != null && contentHeader.indexOf("multipart/form-data") != -1); if (isMultipart == false) { return Helper.errorResponse("not multipart"); } else { DefaultMultipartHttpServletRequest reqM = (DefaultMultipartHttpServletRequest) request; MultiValueMap<String, MultipartFile> fileMap = reqM.getMultiFileMap(); MultipartFile copyIn = fileMap.get("copy-path-in").get(0); MultipartFile copyOut = fileMap.get("copy-path-out").get(0); } System.out.println(response.getContentType()); response.setContentType("application/json"); ModelAndView mav = Helper.successResponse("success"); return mav; } 

The answer is back:

 ModelAndView: reference to view with name 'json'; model is {model={data={"success":true,"info":"success","dataLength":0,"data":[]}}} 

Any ideas?

+4
source share
3 answers

Ok, I misconfigured the response header

  response.setContentType("application/json"); 

not enough.

  MappingJacksonJsonView view = new MappingJacksonJsonView(); view.setContentType("text/html"); Map<String, Object> responseMap = new HashMap<String, Object>(); responseMap.put("success", true); ModelAndView mav = new ModelAndView(view, responseMap); 

Works correctly.

+3
source

I just want to convey the answer to the success function that is performed.

You already have a response from the server in your function of success !. The action parameter in the success function contains information about your response. You can get the answer through action.result.variablename .

0
source

The server response type should be "text / html". The result of asp.net mvc:

 return Json(new { success = true, msg = "Your file has been uploaded", data = new { name, size } }, "text/html"); 

Live demo here

0
source

Source: https://habr.com/ru/post/1345864/


All Articles