【发布时间】:2013-06-25 17:19:02
【问题描述】:
Ajax 正在发送到 PHP
Ĺ asija-kabina
代替
Šasija-kabina
虽然我确实在任何地方声明了字符集。 在 html 文件的头部我有这个:
<meta charset="ISO-8859-2">
在 PHP 文件中我有这个:
header('Content-Type: text/html; charset=latin2');
这是我的 ajax 函数,其中“str”是一个 json 数组:
function updateField(str, id, prevvalue, value, vehicletype){
$.ajax({
type: "get",
url: "inc/ajax/form_rest.php",
data: { q:str, prevvalue:prevvalue, value:value, vehicletype:vehicletype },
contentType: "application/json;charset=latin2",
success: function(html) {
$('#'+id).html(html);
}
})
.done(function(){
$("#"+id).removeAttr("disabled");
if($("#"+id+" option").length == 2){
$("#"+id).val($("#"+id+" option:last-child").val()).change();
}
if($("#"+id+" option:last-child").val() == ""){
$("#"+id).attr("disabled", "disabled");
}
});
}
尽管如此,我得到了错误的输出。谁能帮我解决这个问题?
【问题讨论】:
-
只是猜测,为什么不是 utf-8?
-
UTF-8 不起作用我试过了。它显示问号
-
我很确定你不能在
$.ajax中设置contentType。 stackoverflow.com/questions/3175091/… -
这是我的 contentType 来源:stackoverflow.com/questions/8285936/how-to-change-ajax-charset 我尝试了您在链接中所说的内容,但对于这些字符,它仍然以黑色菱形显示问号
标签: php html ajax json character-encoding