Reading In Utf-8 File (javascript Xmlhttprequest) Gives Bad European Characters
Solution 1:
Probably your file is not in UTF-8 then try this from javascript:
var request = new XMLHttpRequest();
request.open("GET", path, false);
request.overrideMimeType('text/xml; charset=iso-8859-1');
Solution 2:
I'm having the same issue and I fixed in this way.
If you serve the js file containing the spanish days as UTF-8 and the if is NOT saved as UTF-8 it WONT work.
Save the file in your IDE as UTF-8 (ie. eclipse default for js files will be cp1252) and also serve it as UTF-8 char encoding.
If your app is java, do a filter with this code:
response.setCharacterEncoding("UTF-8");
have a good one
Solution 3:
EDIT: Seems that this answer, although accepted, is suboptimal, so for anyone coming here with a similar problem, check out Ricardo's answer
I think you have to use a different way to print the characters, for example, see the code at the end of this discussion:
<script>functiongetUnicode(num) {
num = num.toString(16);
if (num.length < 3) {
for ( var i = num.length; i < 4; i++) {
num = '0' + num;
}
}
return ( "&#" + num + ";" );
}
for ( var i = 0; i < 65355; i++) {
document.write(getUnicode(i));
}
</script>
Solution 4:
I also faced the same issue,I have solved in this way,
While In Get request, we are sending data through url So i decoded the url and get requested parameter through string operations
Consider if you are sending url like this, var ur1="getSubjectList.jsp"; ur1 +="?subjectlist=" +str+"&examId="+examId;
xmlHttp.open("GET", ur1, true); xmlHttp.send(null);
In getSubjectList.jsp, Use this-- String decodedParams= URLDecoder.decode(request.getQueryString(),"utf-8" );
String params[]=decodedParams.split("&");
String subjectlist[]=params[0].split("=");
String examId[] = params[1].split("=");
String center = subjectlist[1];
String exam = examId[1];
In this way,You can get the requested values
Post a Comment for "Reading In Utf-8 File (javascript Xmlhttprequest) Gives Bad European Characters"