weixin_33674976 2015-11-30 08:44 采纳率: 0%
浏览 4

来自AJAX的错误字元集

When I want to printout the output of jQuery AJAX, which has been recived from server. It doesn't show the right charset. What I want exactly is to get š instead I am getting ? or without using utf8_decode() when sending data from server, I get ĹĄ. All files script.js and server php proceed.php are saved in UTF-8 and set in UTF-8. Database is set to UTF-8 as well. All other request from database give the right charset. I've tried most of the things. In .js file for AJAX:

  $.ajaxSetup({
    url: "proceed.php", //file to procces data
    ContentType : 'charset=UTF-8', // tried here
    global: false,
    type: "POST", 
    dataType: "html" // change to text/html, application/text doesnt work at all
});

In .php file:

mysql_query("SET NAMES utf8");
$output = utf8_decode($sql_result);

All possible combinations.

CODE: PHP

if(!empty($_POST['select_had'])){
$zem = $_POST['select_had'];
$vysledek = mysql_query("SELECT typ_hadanky, jazyk FROM hlavolam RIGHT JOIN hadanka ON hlavolam.id_hlavolamu=hadanka.id_hlavolamu WHERE zeme_puvodu='$zem'");
$out = "";
while ($zaznam = mysql_fetch_array($vysledek)) {
    $zaz = $zaznam['jazyk'];
    $out .= "<option>".$zaz."</option>";
}
$vys = utf8_decode($out);
echo $vys;

}

jQuery:

$("#sel_had_zem").change(function(){
var select_had = $("#sel_had_zem option:selected").text();
$.ajax({
  data:{'select_had':select_had},
  success: function(data){
      $("#sel_had_jaz option").nextAll().remove();
      $("#sel_had_jaz").append(data);
  },
  error: function(){
      alert('No server response');
  }
 });

});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
    • ¥15 安装quartus II18.1时弹出此error,怎么解决?
    • ¥15 keil官网下载psn序列号在哪
    • ¥15 想用adb命令做一个通话软件,播放录音
    • ¥30 Pytorch深度学习服务器跑不通问题解决?
    • ¥15 部分客户订单定位有误的问题
    • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
    • ¥15 Bug traq 数据包 大概什么价
    • ¥15 在anaconda上pytorch和paddle paddle下载报错
    • ¥25 自动填写QQ腾讯文档收集表