通过ajax提交时,德语特殊字符会卡住

cyp*_*r75 5 php ajax jquery utf-8

我通过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);
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

在这个例子中,'type'的值为'Müller'.在我的'ajax.results.php'中我这样做:

<?= $_GET['type'] ?>

// Output is 'Müller' in Firefox and Chrome

// BUT in internet explorer the output is 'M'
Run Code Online (Sandbox Code Playgroud)

所以,它适用于Firefox和Chrome,但在Internet Explorer中,结果为'M'(M后跟一个正方形)......

我试图像这样改变输出:

<?= utf8_encode($_GET['type'] ?>

// Output in internet Explorer now is fine (Müller)

// BUT in Firefox and Chrome it is 'Müller'
Run Code Online (Sandbox Code Playgroud)

由于输出必须通过PHP(因为我会用它做进一步的操作),我找不到解决方案......

有谁可以帮忙解决这个问题?非常感谢

cyp*_*r75 2

感谢你的帮助。

我自己找到了解决方案:我已将“encodeURIComponent()”添加到我的 ajax 请求中并且它有效:-)

$( document ).ready(function() {
    $('#dropdown').change(function() {
        $.ajax({
            url: "inc/ajax.results.php",
            type: "GET",
            data: 'type='+encodeURIComponent($('#type').val())
        }).done(function(data){
            $("#results").html(data);
        });
    });
});
Run Code Online (Sandbox Code Playgroud)