ajax - JavaScript JSON.parse UTF-8 problems -


i have page makes request php file via ajax, , ajax file displays json response, , i've got issues it.

it results page uses utf-8 charset in order display special chars, etc; ajax file used ansi encoding default decided change utf-8 correct symbols too, when use json.parse throws me error "uncaught syntaxerror: unexpected token", (if ajax file encoded utf-8), change ansi , works great, don't know why json has behaviour.

when @ output (xhr.responsetext) both ansi , utf-8 identical (i'm not using special chars in utf-8).

maybe json.parse doesn't accept response utf-8 files (something don't believe) or have set header in order fix that? guys think it? thank you..

i had faced same problem. used following encode functions instead of default encode function. gives me perfect result

function json_encode_utf8($arr) {   array_walk_recursive($arr, 'encode_utf8');   return mb_decode_numericentity(json_encode($arr), array(0x80, 0xffff, 0, 0xffff), 'utf-8'); }  function encode_utf8(&$item, $key) {   if (is_string($item))     $item = mb_encode_numericentity($item, array(0x80, 0xffff, 0, 0xffff), 'utf-8'); }  $group_members = array('matthias  schöbe');  $group_members_json = json_encode_utf8($group_members); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -