weixin_33713503 2016-04-11 16:06 采纳率: 0%
浏览 29

特殊字符问题

I am facing an issue where special characters are not being printed properly on my webpage.

So, I am making an ajax query, with python script at backend :

$.ajax({                                                                       
    url: BACK_END_LOC + 'get_search_results',                                  
    data: ({keyword1: keyword1,                                                
            keyword2: keyword2,                                                
            start_time: encodeURI(start_time),                                 
            end_time: encodeURI(end_time),                                     
            dataset: $("#dataset").val()                                       
            }),                                                                

    success: function(data) {                                                  
        response = eval('(' + data + ')');                                     
        if (response.error_code == 0) {                                        
            render_event_search_results(response.data);                        
        } else {                                                               
        alert('Error_code:' + response.error_code + ', Error_msg:' + response.error_msg);
        }                                                                      
    },  

Python is returning a json object:

def get_search_results(req, keyword1, keyword2, start_time, end_time, dataset):
s = keyword1 + "," + keyword2

# get filtered events
results = get_filtered_events(dataset, keyword1, keyword2, start_time, end_time)

try:
    r = {'error_code': 0, 'error_msg': 'OK', 'data': results}

except Exception, e:
    raise e
    r = {'error_code': 1, 'error_msg': 'Oops'}

return simplejson.dumps(r)

Now, one field of this object has special characters. When I try to print this field on html "alert(gEvents[0].signature)", it is being printed as : \u0432\u0438\u0434\u0435\u043e_storm

How can I get it printed like :видео_storm, which is the actual text.

  • 写回答

1条回答 默认 最新

  • weixin_33716557 2016-04-11 16:25
    关注

    replace

    return simplejson.dumps(r)
    

    with

    return simplejson.dumps(r,ensure_ascii=False)
    
    评论

报告相同问题?

悬赏问题

  • ¥20 白日门传奇少一个启动区服和启动服务器的快捷键,东西都是全的 , 他们说套一个出来就行了 但我就是弄不好,谁看看,
  • ¥100 如何用js写一个游戏云存档
  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子