[英]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.