您的位置:首页 > 运维架构 > Linux

在CentOS7上安装使用Ansibel(自动化工具)Install and use Ansible (Automation Tool) in CentOS 7

2016-04-02 08:10 976 查看
Q:

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 this fields
are submitted with UTF-8.

Does anyone know, how can i set encoding in $.getJSON calls?

 

 

A:

 

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);
}
});

 

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.

 

 

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

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: