php - 当数据库中存在特殊字符时,Ajax不返回结果集

标签 php jquery mysql ajax json

当我尝试使用 json 格式的 ajax 从 UTF-8 编码的数据库获取数据并且数据包含特殊字符(如 Ä,Ö,Ü,ä,ö,ü,... 时,结果集为空!

$('.club-details').click(function() {
    var element = $(this);
    var data = {
        gid: $(this).parent().parent().parent().parent().data('gid'),
        club_number: $(this).parent().parent().data('club')
    };
    $.ajax({
        type: 'POST',
        url: TRANSFER_CALLS_URI,
        data: 'key=getClubDetails&data=' + JSON.stringify(data),
        dataType: 'json',
        success: function(response) {
            var html = "";
            html += "<table>";
            html += "   <tr>";
            html += "       <td>Name kurz</td>";
            html += "       <td>" + response[0].name_short + "</td>";
            html += "   </tr>";
            html += "   <tr>";
            html += "       <td>Schießstätte</td>";
            html += "       <td>" + response[0].location + "</td>";
            html += "   </tr>";
            html += "   <tr>";
            html += "       <td>Telefon</td>";
            html += "       <td>" + response[0].phone + "</td>";
            html += "   </tr>";
            html += "</table>";
            element.unbind('click').popover({
                content: html,
                title: 'Vereinsinformation',
                html: true,
                placement: 'bottom'
            }).popover('show');
        },
        error: function() {
            $.error('Ajax');
        }
    });
});

不含德语特殊字符的数据记录将成功接收并显示。

最佳答案

您应该检查浏览器的编码、服务器端语言、数据库连接、数据库、表、列。确保所有这些都是 UTF-8。

关于php - 当数据库中存在特殊字符时,Ajax不返回结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19808774/

相关文章:

php - jQuery - 保存/使用cookie

php - 如何从 Node.js 调用 PHP Web 服务

javascript - 精确比较 $(window).height() 值与滚动的特定值

mysql - 更改 MySQL Workbench 中的语法突出显示颜色

mysql - 如果我们要传递的列表很大,则获取 mysql 中行数的最佳实践

php - 正在发送 POST header ,但未在服务器上接收到

php - Laravel 条件语句 when 用于过滤值

javascript - 从其他按钮点击触发按钮

jquery错误: Object expected

mysql - 从MySQL表中删除重复的连续数据