doushun1870 2013-03-20 10:40
浏览 26
已采纳

当ajax响应编码中的西里尔字符错误时[重复]

This question already has an answer here:

I have the fallowing Cyrillic string i want to return in my ajax response : 'Този еmail е вече регистриран'.

How ever when i do this:

<?php
    public function echoCyrllic(){
        $json['error']='Този еmail е вече регистриран';
        echo json_encode($json);
    }
 ?>

My response is this:

{"error":"\u0422\u043e\u0437\u0438 \u0435mail \u0435 \u0432\u0435\u0447\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0430\u043d"}

Can anybody help. Thanks.

</div>
  • 写回答

1条回答 默认 最新

  • dongwei1895 2013-03-20 10:43
    关注

    this json is valid... even though it looks dirty.. the json will decode it correctly

    try it out

     alert(reponse.error);
    

    if in case you don't want as such then.. send error as text and use condition to display this where you wanted..

    like

     $json['error']='error';
     echo json_encode($json);
    

    and in javascript

    if(response.error == "error"){
         alert('Този еmail е вече регистриран');
    }
    

    however, this is just another way to do it.. but i prefer to go with the first one.. since there is nothing wrong with the first one.. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器