In my web app, I submit some form fields with jQuery's $.getJSON()
method. I am having some problems with the encoding. The character-set of my app is charset=ISO-8859-1
, but I think these fields are submitted with UTF-8
.
How I can set encoding used in $.getJSON
calls?
If you want to use $.getJSON()
you can add the following before the call :
$.ajaxSetup({ scriptCharset: "utf-8", contentType: "application/json; charset=utf-8" });
You can use the charset you want instead of utf-8
.
The options are explained here.
contentType :
When sending data to the server, use this content-type
. Default is application/x-www-form-urlencoded
, which is fine for most cases.
scriptCharset :
Only for requests with jsonp
or script
dataType and GET type. Forces the request to be interpreted as a certain charset. Only needed for charset differences between the remote and local content.
You may need one or both ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With