Charset problem with Safari und Chrome
Hi
In the sync function i have found a problem with charsets. Firefox and IE will send automaticly the charset, but safari and chrome not. So i have a site with utf-8 and i send new data from model to my api. an then the data will come with iso-8859-1 and that is very bad.
so now i have change following and it works for me.
from params.contentType = 'application/json'; to params.contentType = 'application/json charset=UTF-8';
i think this is correct!?
-Thierry
I don't think you should need to manually send the charset. Perhaps you have a problem in your server-side configuration. Can anyone else confirm?
Looking through the spec I think technically you should
@braddunbar and I were talking about maybe basing on document.characterSet and allowing an option to override?
My question is -- is anyone else encountering this problem? I would have thought it would have raised it's head long ago if it's real -- I've never seen this in Backbone/Rails apps.
I've never encountered it before, but all the apps I work with use UTF-8 exclusively.
I can confirm the behavior - that chrome will send "Content-Type:application/json" and Firefox "Content-Type application/json; charset=UTF-8" - though based on my testing it hasn't made any difference to the data recorded on the server side nor to what gets recorded. - sending some known characters which are in UTF-8 and not in ISO-8859-1.
@nischi - do you have a test case where this causes a problem?
Yes. I'm from Switzerland, and here we have german umlaut. Sample: Störchelstrasse
When i would transfer this string, backbone send St%A!rchelstrasse or similiar.
Well you know it's interesting, in chrome dev tools it does say that that's what's being sent in the 'Request Payload', though on the server side it gets recorded just fine and gets returned fine in the response from the put request.

If your code only works with the addition, maybe your server side code (or the platform you're working with) is doing some charset selection based on the 'Content-Type' header and is defaulting to ISO-8859-1 (or something else)
But i have check the server side. thats my first idea. but there is all on utf-8. only the server it self, or the IIS make some special. But, when i put the UTF-8 manual in backbone.js, so chrome have the right chars in the Requeset Payload. So i think that would be correct. And with the manual UTF-8 in the backbone.js works in chrome and safari too. It's a little bit strange when different browser send different charsets. What do you think?
Having exactly the same issue (also with swiss characters)
Are you using iis as well @narenranjit ?
i have the same issue also with tomcat from Railo 4
@mdekmetzian Server: Apache/2.2.20 (Ubuntu)
@nischi - my application is tomcat / jax-rs / jersey, and it works with or without the charset=UTF-8 under chrome / safari. Tested chrome under win/osx and safari on osx without issue.
I went through and reconfirmed all the above in my environment just to be sure it wasn't affecting our users, which it isnt.
@jashkenas @tgriesser I still think their issue is server-side, but at the same time, adding the charset doesn't hurt any of the above and would remove a pain point for at least some of the users.
The server-side fix sounds correct -- and you should also be able to specify the charset in your HTML meta tags, I believe. In any case, us shoving it in the content-type seems fairly wrong -- and I can just anticipate us cutting a release with that change in there, and getting a slew of bugs from folks whose simpleminded servers don't understand a content-type so bizarre. Closing.
Just try setting the content-type in client request instead of trying at server. That solved my problem. And I guess that is correct because the client should decide what encoding he should sent.