Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set encoding in .getJSON jQuery

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?

like image 279
Sergio del Amo Avatar asked Aug 25 '08 18:08

Sergio del Amo


1 Answers

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 ...

like image 84
Pat Avatar answered Sep 19 '22 02:09

Pat