我正在通过 jquery.ajax 向结果 div 提交参数(包括特殊字符,如 ä、ö、ü)。在那个 div 中,我需要用 php 处理它。
例如:
$( document ).ready(function() {
$('#dropdown').change(function() {
$.ajax({
url: "inc/ajax.results.php",
type: "GET",
data: 'type='+$('#type').val()
}).done(function(data){
$("#results").html(data);
});
});
});
在此示例中,“type”的值为“Müller”。在我的“ajax.results.php”中,我这样做:
<?= $_GET['type'] ?>
// Output is 'Müller' in Firefox and Chrome
// BUT in internet explorer the output is 'M'
因此,对于 Firefox 和 Chrome 来说没问题,但在 Internet Explorer 中,结果是“M”(M 后跟一个方 block )...
我试过像这样改变输出:
<?= utf8_encode($_GET['type'] ?>
// Output in internet Explorer now is fine (Müller)
// BUT in Firefox and Chrome it is 'Müller'
由于输出必须通过 PHP(因为我将用它做进一步的操作),我找不到解决方案...
谁能帮忙解决这个问题? 非常感谢
最佳答案
在有下拉菜单的 HTML 页面上,插入
<meta charset="utf-8">
或
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
在标签内。
并确保将所有文件保存为 UTF-8(或更好:不带 BOM 的 UTF-8)
Apache 服务器默认配置为提供 ISO-8859-1 中的文件,因此您需要将以下行添加到您的 .htaccess 文件中:
AddDefaultCharset UTF-8
关于php - 通过 ajax 提交时,德语特殊字符卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28041029/