Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This happens because AJAX-calls by default use browser's default encoding (f.e. ANSI). For overriding this you need to do:</p> <p>jQuery <a href="http://api.jquery.com/jQuery.ajax/">style</a> - <strong>mimeType</strong>:</p> <pre><code>$.ajax({ url: "get_label", mimeType:"text/html; charset=UTF-8", success: function(result) { alert(result); $("#parameter_select label").text(result); } }); </code></pre> <p>Vanilla JS <a href="https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#overrideMimeType%28%29">style</a>:</p> <pre><code>xhr.overrideMimeType("text/html; charset=UTF-8") </code></pre> <p>But from the other hand you need to be sure, that server also returns appropriate response. For this you need to check the following:</p> <ol> <li>Add UTF-8 support for web-container (i.e. Tomcat) with adding <strong>URIEncoding="UTF-8"</strong> for your <strong>Connector</strong> settings in <strong>server.xml</strong>; check <a href="http://struts.apache.org/release/2.0.x/docs/how-to-support-utf-8-uriencoding-with-tomcat.html">this</a> for more information.</li> <li>If previous change didn't help (though it has to), please also make sure, that servlet response's character set is also <strong>UTF-8</strong>.</li> </ol> <p>For this you can use either explicit call of method:</p> <pre><code>@RequestMapping("get_label") public @ResponseBody String getLabel(HttpServletResponse response) { String str = "בדיקה"; //set encoding explicitly response.setCharacterEncoding("UTF-8"); return str; } </code></pre> <p>Or, which seems to be more preferable for <code>@ResponseBody</code> and Spring 3.1+:</p> <pre><code>@RequestMapping(value = "get_label", produces = "text/html; charset=UTF-8") public @ResponseBody String getLabel(HttpServletResponse response) { String str = "בדיקה"; return str; } </code></pre> <p>As a conclusion I would like to clarify, that for proper handling of AJAX-calls with UTF-8 encoding, you have to make sure, that:</p> <ul> <li>web-container supports this properly</li> <li>response's character encoding is UTF-8</li> <li>AJAX request character encoding is also UTF-8</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload