我在 Internet Explorer 中使用 ajax 显示 json 响应时遇到问题。其他浏览器正确显示它。但在 Internet Explorer 中显示为??????。
响应 header 是
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":"??????????????"}}
在所有其他浏览器中都能正确显示
最佳答案
我已经找到了答案。这是服务器的问题。我们必须在服务器中将响应内容类型设置为 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
关于javascript - Internet Explorer 中的 Json 响应问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34938800/