Internet Explorer中的Json响应问题

时间:2016-01-22 04:04:16

标签: javascript json internet-explorer response

我在使用Internet Explorer中的ajax显示json响应时遇到问题。其他浏览器正确显示它。但在Internet Explorer中它显示为??????。

响应标头

Key Value
Response    HTTP/1.1 200 OK
Server  Apache-Coyote/1.1
Pragma  no-cache
Cache-Control   private, max-age=0, no-store, no-cache
Expires Fri, 22 Jan 2016 03:50:17 GMT
Cache-Control   no-cache, no-store, max-age=0, must-revalidate
Pragma  no-cache
Expires 0
X-XSS-Protection    1; mode=block
X-Frame-Options SAMEORIGIN
X-Content-Type-Options  nosniff
Content-Type    text/html;charset=UTF-8
Content-Length  145
Date    Fri, 22 Jan 2016 03:50:17 GMT

但在Internet Explorer中,响应正文为

 {"data":null,"status":2,"message":"Request succeeded","errors":{"data1":"??????????????","data2":"??????????????"}}

在所有其他浏览器中,它正确显示

1 个答案:

答案 0 :(得分:1)

我找到了答案。它在服务器中存在问题。我们必须在服务器中将响应内容类型设置为text / plain。以下是解决我问题的代码。

   @RequestMapping(value = "/uploading", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
public @ResponseBody
String upload(@RequestParam(value = "file", required = false) MultipartFile file, Locale locale) {
//opertions here
return jsonSerializer.serialize(message);
}

有关详细信息,请浏览链接 UTF-8 encoding problem in Spring MVC