【问题标题】:ajax database request not returning German characters?ajax 数据库请求不返回德语字符?
【发布时间】:2013-08-03 18:25:58
【问题描述】:

我从中获取数据的表位于“Latin_1”中,但是当返回数据时,其中包含德语字符的字段将返回为空。 为什么要这样做? json 编码会影响字符集吗? 除此之外,我完全迷失了。

我读过你可以在 php 中设置字符集,但它已经设置正确并且表格中有特殊字符?

编辑//

这是我正在使用的代码 __php:

function getInfo($country){

    $rows = array();
    $query = "SELECT name,add1,add2,town,district,postcode FROM stockistsWorld WHERE country = '". mysql_escape_string($country) ."' LIMIT 4 ";
    //$query = "SELECT Name,add1 FROM stockistsUK LIMIT 10";
    $result = mysqli_query($this->conn, $query);
    /* numeric array */

    while($row = mysqli_fetch_array($result, MYSQLI_NUM)){

         $rows[] = $row;

        }

    return $rows;
}

这是 ajax 请求__

function ajaxData(country){
//get data from database return into inf array 
var infArray = new Array();
 $.ajax({
        type: 'POST',
        url: 'php/Maps.php',
        data: {country: country},
        success: function(data){
        infArray = JSON.parse(data);
        geoCodeClientSide(infArray);
        }           
    });

}

【问题讨论】:

标签: php ajax database char set


【解决方案1】:

请将您的 db/table 的字符集设置为 utf-8。

谢谢, 新

【讨论】:

  • 我已经把它改成了这个,但它仍然没有返回变音符号?我以为 utf 8 不支持这个?
  • 请手动查看表格中的具体数据,你能看懂那些字符吗?如果没有,则需要在将字符集更改为 utf-8 后再次插入数据
  • 在我的 sql 中,如果我查询数据库会出现特殊字符
  • 好的,您能在将“数据”转换为 JSON 之前打印它并检查它是否正常吗?
  • 我认为您的 html/php 无法将 chrset 呈现为 utf-8。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-05
相关资源
最近更新 更多