IE + json + MultipartFile + ajax = Download Popup ?

나를 날새게 한 문제는 니가 처음이 아니야

< BEFORE >

AJAX in jsp : 
$("#createForm").ajaxForm({
 url:url,
 dataType:'json',
 type:'POST'
}).submit();


java Controller :

@RequestMapping(value = "url", method = RequestMethod.POST)
@ResponseBody
public JsonObject create(@RequestParam("file") MultipartFile file){
    JsonObject jo = new JsonObject(); 
    jo.set("result", true); 
    return result; 
}

이렇게 하면 IE에서는 .json 형태의 파일을 다운로드 하겠냐는 팝업이 뜬다.

그래서 아래처럼 고치면 해결! 

< AFTER >


AJAX in jsp : 
$("#createForm").ajaxForm({
 url:url,
 dataType:'json', 
 type:'POST'
}).submit();


java Controller:

@RequestMapping(value = "url", method = RequestMethod.POST)
public ResponseEntity create(@RequestParam("file") MultipartFile file){
 JsonObject jo = new JsonObject();
 jo.set("result", true);
 HttpHeaders responseHeaders = new HttpHeaders();
 responseHeaders.add("Content-Type", "text/html; charset=UTF-8"); 
 return new ResponseEntity(jo, responseHeaders, HttpStatus.CREATED);
}


덤으로
혼자 아래처럼 수정해봤는데 실패했었다. 이유는 모르겠다...:-( 

 
  text/plain;charset=UTF-8
 

댓글

  1. 같은 문제로 고민중이였는데..감사합당

    답글삭제
  2. 저도 감사드립니다. 한참 고생했는데 해결하였습니다.

    답글삭제

댓글 쓰기

가장 많이 본 글