如何在.getJSON JQuery中设置编码 [英] How to set encoding in .getJSON JQuery
问题描述
在我的网络应用程序中,我使用jQuery $。getJSON()
方法提交一些表单字段。我有一些编码的问题。我的应用程序的字符集是 charset = ISO-8859-1
,但我认为这些字段提交与 UTF-8
。
In my web app, I submit some form fields with jQuery $.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
.
有人知道,我如何在 $。getJSON
调用中设置编码?
Does anyone know, how I can set encoding in $.getJSON
calls?
推荐答案
我认为你可能需要使用 $。ajax()
如果要更改编码,请参阅 contentType
param下面(成功
和错误
回调假设你有< c $ c>< div id =success>< / div> 和< div id =error>< / div> code> in the html):
I think that you'll probably have to use $.ajax()
if you want to change the encoding, see the contentType
param below (the success
and error
callbacks assume you have <div id="success"></div>
and <div id="error"></div>
in the html):
$.ajax({
type: "POST",
url: "SomePage.aspx/GetSomeObjects",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{id: '" + someId + "'}",
success: function(json) {
$("#success").html("json.length=" + json.length);
itemAddCallback(json);
},
error: function (xhr, textStatus, errorThrown) {
$("#error").html(xhr.responseText);
}
});
我实际上只是在一个小时前做这件事,是什么巧合!
I actually just had to do this about an hour ago, what a coincidence!
这篇关于如何在.getJSON JQuery中设置编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!