[英]Ajax character encoding changed after send to server
我有一个像这样的ajax:
$.ajax('../EditUser?userId=' + editingId + '&full_name=' + name + '&position=' + position + '&office=' + office
+ '&office_address=' + office_address + '&age=' + age + '&user_login_name=' + user_login_name + '&email=' + email
+ '&user_type=' + usertype + '&password=' + password + '&meetingIds=' + selectedmeetingid, {
type: 'POST',
success: function (data) {
if (data.indexOf('error://') < 0) {
$('#tbl_meetings').html(data);
} else {
$('#errorMessage').html(data);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert("error " + errorThrown);
alert("error " + textStatus);
alert("error " + jqXHR.status);
}
}
);
并且我的服务器接收到的数据编码错误,例如:在服务器端收到“HàThịMinhThắng”后变成“ H?Th?Minh Th?ng”。我尝试添加
contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
和
beforeSend: function(jqXHR) {
jqXHR.overrideMimeType('text/html;charset=iso-8859-1');
}
到我的ajax,但没有用。 那么,有人知道如何解决此问题吗?
尝试为ajax请求指定内容类型,并且必须在服务器端添加标头以接收字符集。
$.ajax({ data: parameters, type: "POST", url: your-url, timeout: 20000, contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1", dataType: 'json', success: callback }); // Server Side... (This is an example in php which I have used in my app) header('Content-Type: text/html; charset=ISO-8859-1');
希望这对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.