This is because, by default, AJAX calls use the default encoding of the browser (for example, ANSI). To do this, you need to do the following:
jQuery style - mimeType :
$.ajax({
url: "get_label",
mimeType:"text/html; charset=UTF-8",
success: function(result)
{
alert(result);
$("#parameter_select label").text(result);
}
});
Vanilla JS style :
xhr.overrideMimeType("text/html; charset=UTF-8")
, . :
- UTF-8 - ( Tomcat) URIEncoding = "UTF-8" server.xml; .
- ( ), , , UTF-8.
:
@RequestMapping("get_label")
public @ResponseBody String getLabel(HttpServletResponse response)
{
String str = "בדיקה";
response.setCharacterEncoding("UTF-8");
return str;
}
, @ResponseBody Spring 3.1 +:
@RequestMapping(value = "get_label", produces = "text/html; charset=UTF-8")
public @ResponseBody String getLabel(HttpServletResponse response)
{
String str = "בדיקה";
return str;
}
, AJAX- UTF-8 , :