Possible Duplicate:
UTF8 problem with MySQL 5
I'm having trouble displaying "German Umlaute" characters on a HTML page.
The actual page is saved UTF-8 without BOM
encoded, has it's UTF-8 metatag
, it is requested via AJAX and I'm manually setting the response header to UTF-8
, too. Still, all German characters are broken.
I also place another AJAX call for dynamic content, which is returned correctly (in Firebug), but when displayed in the browser, the Umlaute are broken again.
I can fix everything by setting iso-8859-1
in all Ajax response headers, but I thought UTF-8
can handle special characters and I wouldn't have to mix character encoding.
Question:
Shouldn't UTF-8 handle characters correctly? Or do I need another charset? Am I missing something obvious?
Thanks!
EDIT:
Here is a screenshot:
Code next.
EDIT:
THis is what I'm getting back from the server:
And the response header also shows the content being delivered to be UTF-8
So from my unknowing point of view, the server response seems to be correct in UTF-8
and foreign characters showing, is it so?
The actual page is requested by Jquery Mobile, so I can't say what's happening there. The dynamic content, I'm doing myself. This is the call from my application controller:
var form = "",
service = "../services/views.cfc",
method = "byPass",
returnformat = "json",
targetUrl = "",
formdata = "form_submitted=getUsers&method="+method+"&returnformat="+returnformat,
successHandler = function(objResponse, cbk) {
cbk( objResponse );
};
ajaxFormSubmit( form, service, formdata, targetUrl, successHandler, "yes", "", returnformat, cbk );
which triggers:
var ajaxFormSubmit =
function ( form, service, formdata, targetUrl, successHandler, dataHandler, errorHandler, returnformat, type ){
var override = null;
if ( type !== "" && type !== "post" ){
override = type;
type = "get";
}
$.ajax({
async: false,
type: type == "" ? "get" : type,
url: service,
data: formdata,
dataType: returnformat,
success: function( objResponse ){
if (objResponse.SUCCESS == true || typeof objResponse === "string" ){
dataHandler == "yes" ? successHandler( objResponse, override ) : successHandler( override );
} else {},
error: function (jqXHR, XMLHttpRequest, textStatus, errorThrown) {}
});
}
On the server (I'm using Coldfusion8
and MySQL 5.0.88
. I'm ending up in this view:
<cffunction name="getUsers_abc" access="public" returntype="any" output="false" hint="JSON vcard library">
<cfargument name="local" type="struct" required="true" hint="Local Object" />
<cfscript>
var THAT = local;
THAT.displayStart = 0;
THAT.displayLength = 10;
THAT.count = 0;
THAT.loginid = Session.id;
</cfscript>
<cftry>
<!--- Database call --->
<cfquery datasource="#Session.datasource#" name="getUsers">
SELECT
tn.iln,
tn.typ,
...
FROM table AS Tn
WHERE tn.freigeschaltet != "5"
AND tn.typ = "abc"
LIMIT #THAT.displayStart#,#THAT.displayLength#
</cfquery>
<!--- CREATE JSON --->
<cfsavecontent variable="jsonRetailers">
<cfoutput>{"data":[</cfoutput>
<cfloop query="getUsers">
<cfset THAT.count = THAT.count + 1>
<cfoutput>
<cfoutput>{</cfoutput>
<cfoutput>"type":"#getUsers.typ#",</cfoutput>
...
<cfoutput>}]</cfoutput>
<cfoutput>}</cfoutput>
</cfoutput>
<cfif getUsers.recordcount LT THAT.displayStart + THAT.displayLength>
<cfif THAT.count is not getUsers.recordcount><cfoutput>, </cfoutput></cfif>
<cfelse>
<cfif THAT.count LT THAT.displayLength><cfoutput>, </cfoutput></cfif>
</cfif>
</cfloop>
<cfoutput>]</cfoutput>
<cfoutput>,"SUCCESS":true,"Count":#getUsers.recordcount#}</cfoutput>
</cfsavecontent>
<cfset variables.alredayBinary = "false">
<!--- GZIP if possible --->
<cfif cgi.HTTP_ACCEPT_ENCODING contains "gzip">
<cfinvoke method="gzip" stringToZip="#jsonRetailers#" returnvariable="passBackObject"></cfinvoke>
<cfheader name="Content-Encoding" value="gzip">
<cfset variables.alredayBinary = "true">
</cfif>
<!--- setting UTF-8 --->
<cfheader name="Content-Type" value="text/json; charset=UTF-8">
<cfheader name="Content-Length" value="#len(passBackObject)#" >
<cfif variables.alredayBinary EQ "false">
<!--- send to browser --->
<cfcontent reset="no" variable="#CharsetDecode(passBackObject, "UTF-8")#" />
<cfelse>
<cfcontent reset="no" variable="#passBackObject#" />
</cfif>
<cfreturn />
</cffunction>
So, no PHP unfortunately. THe code is not telling me where the problem is, but maybe you see something, I don't .
Thanks!