Why non-ascii chars are displayed as weird symbols?

后端 未结 3 1416
盖世英雄少女心
盖世英雄少女心 2021-01-20 11:44

I have 2 cases here:

My Database contains lots of info which I want to fetch to the page, some of these info are name which contain non-ascii chars like Uwe Rü

3条回答
  •  难免孤独
    2021-01-20 12:30

    Thanks to Aaron Digulla's answer, I followed the string from server to the page and found that it is gets misrepresented after the AJAX LOAD, so I found this answer which resolved my problem. Although I had to use the charset="iso-8859-1" for it to work rather than charset="UTF-8".

    So the final answer is:

    -Encoding in the HTML page:

    
    

    -Encoding the Ajax data:

     $.ajaxSetup({
              'beforeSend' : function(xhr) {
               xhr.overrideMimeType('text/html; charset=iso-8859-1');
            },
        });
    

    And now chars are displayed correctly. Thanx for your help guys..

提交回复
热议问题