<p>In my web app, I submit some form fields with jQuery's <code>$.getJSON()</code> method. I am having some problems with the encoding. The character-set of my app is <code>charset=ISO-8859-1</code>, but I think these fields are submitted with <code>UTF-8</code>. </p>

<p>How I can set encoding used in <code>$.getJSON</code> calls? </p>

[{'answer_id': 26681, 'author': 'travis', 'author_id': 1414, 'author_profile': 'https://Stackoverflow.com/users/1414', 'pm_score': 6, 'selected': True, 'text': '<p>I think that you\'ll probably have to use <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options" rel="noreferrer"><code>$.ajax()</code></a> if you want to change the encoding, see the <code>contentType</code> param below (the <code>success</code> and <code>error</code> callbacks assume you have <code>&lt;div id="success"&gt;&lt;/div&gt;</code> and <code>&lt;div id="error"&gt;&lt;/div&gt;</code> in the html):</p>\n\n<pre><code>$.ajax({\n    type: "POST",\n    url: "SomePage.aspx/GetSomeObjects",\n    contentType: "application/json; charset=utf-8",\n    dataType: "json",\n    data: "{id: \'" + someId + "\'}",\n    success: function(json) {\n        $("#success").html("json.length=" + json.length);\n        itemAddCallback(json);\n    },\n    error: function (xhr, textStatus, errorThrown) {\n        $("#error").html(xhr.responseText);\n    }\n});\n</code></pre>\n\n<p>I actually just had to do this about an hour ago, what a coincidence!</p>\n'}, {'answer_id': 27023, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 6, 'selected': False, 'text': '<p>If you want to use <code>$.getJSON()</code> you can add the following before the call :</p>\n\n<pre><code>$.ajaxSetup({\n    scriptCharset: "utf-8",\n    contentType: "application/json; charset=utf-8"\n});\n</code></pre>\n\n<p>You can use the charset you want instead of <code>utf-8</code>.</p>\n\n<p>The options are explained <a href="http://docs.jquery.com/Ajax/jQuery.ajax#toptions" rel="noreferrer">here</a>.</p>\n\n<p><code>contentType :</code> When sending data to the server, use this <code>content-type</code>. Default is <code>application/x-www-form-urlencoded</code>, which is fine for most cases.</p>\n\n<p><code>scriptCharset :</code> Only for requests with <code>jsonp</code> or <code>script</code> 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.</p>\n\n<p>You may need one or both ...</p>\n'}, {'answer_id': 8707420, 'author': 'Anderson Mao', 'author_id': 818400, 'author_profile': 'https://Stackoverflow.com/users/818400', 'pm_score': 1, 'selected': False, 'text': '<p>Use <code>encodeURI()</code> in client JS and use <code>URLDecoder.decode()</code> in server Java side works.</p>\n\n<hr>\n\n<p>Example: </p>\n\n<ul>\n<li><p><strong>Javascript</strong>:</p>\n\n<pre><code>$.getJSON(\n    url,\n    {\n        "user": encodeURI(JSON.stringify(user))\n    },\n    onSuccess\n);\n</code></pre></li>\n<li><p><strong>Java</strong>:</p>\n\n<p><code>java.net.URLDecoder.decode(params.user, "UTF-8");</code></p></li>\n</ul>\n'}, {'answer_id': 9606241, 'author': 'Felipe Alcará', 'author_id': 1255308, 'author_profile': 'https://Stackoverflow.com/users/1255308', 'pm_score': 3, 'selected': False, 'text': '<p>You need to analyze the JSON calls using Wireshark, so you will see if you include the charset in the formation of the JSON page or not, for example:</p>\n\n<ul>\n<li>If the page is simple if text / html</li>\n</ul>\n\n<pre>\n0000  48 54 54 50 2f 31 2e 31  20 32 30 30 20 4f 4b 0d   HTTP/1.1  200 OK.\n0010  0a 43 6f 6e 74 65 6e 74  2d 54 79 70 65 3a 20 74   .Content -Type: t\n0020  65 78 74 2f 68 74 6d 6c  0d 0a 43 61 63 68 65 2d   ext/html ..Cache-\n0030  43 6f 6e 74 72 6f 6c 3a  20 6e 6f 2d 63 61 63 68   Control:  no-cach\n</pre>\n\n<ul>\n<li>If the page is of the type including custom JSON with MIME "charset = ISO-8859-1"</li>\n</ul>\n\n<pre>\n0000  48 54 54 50 2f 31 2e 31  20 32 30 30 20 4f 4b 0d   HTTP/1.1  200 OK.\n0010  0a 43 61 63 68 65 2d 43  6f 6e 74 72 6f 6c 3a 20   .Cache-C ontrol: \n0020  6e 6f 2d 63 61 63 68 65  0d 0a 43 6f 6e 74 65 6e   no-cache ..Conten\n0030  74 2d 54 79 70 65 3a 20  74 65 78 74 2f 68 74 6d   t-Type:  text/htm\n0040  6c 3b 20 63 68 61 72 73  65 74 3d 49 53 4f 2d 38   l; chars et=ISO-8\n0050  38 35 39 2d 31 0d 0a 43  6f 6e 6e 65 63 74 69 6f   859-1..C onnectio\n</pre>\n\n<p>Why is that? because we can not put on the page of JSON a goal like this:\n</p>\n\n<p>In my case I use the manufacturer Connect Me 9210 Digi:</p>\n\n<ul>\n<li>I had to use a flag to indicate that one would use non-standard MIME:\n                 p-> theCgiPtr-> = fDataType eRpDataTypeOther;</li>\n<li>It added the new MIME in the variable:\n                 strcpy (p-> theCgiPtr-> fOtherMimeType, "text / html;\ncharset = ISO-8859-1 ");</li>\n</ul>\n\n<p><strong>It worked for me</strong> without having to convert the data passed by JSON for UTF-8 and then redo the conversion on the page ...</p>\n'}, {'answer_id': 26887335, 'author': 'Vipin Kohli', 'author_id': 3167919, 'author_profile': 'https://Stackoverflow.com/users/3167919', 'pm_score': 0, 'selected': False, 'text': '<p>Use this function to regain the utf-8 characters</p>\n\n<pre><code>function decode_utf8(s) { \n  return decodeURIComponent(escape(s)); \n}\n</code></pre>\n\n<p>Example:\n    var new_Str=decode_utf8(str);</p>\n'}, {'answer_id': 58890056, 'author': 'zahra salmaninejad', 'author_id': 11372789, 'author_profile': 'https://Stackoverflow.com/users/11372789', 'pm_score': 0, 'selected': False, 'text': '<p>f you want to use $.getJSON() you can add the following before the call :</p>\n\n<pre><code>$.ajaxSetup({\n    scriptCharset: "utf-8",\n    contentType: "application/json; charset=utf-8"\n});\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/26620', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2138/']