1

I used ajax for the search function. However, it failed to search unicode characters. Here is the code causing a problem

success: function(data){
  var url = base_url + "/?s=ryhmät";
  location.href=url;
}

The url passed correctly, but location.href has the value of encoded characters. like base_url/?s=ryhm%E4t

I tried to use decodeURI/encodeURI functions, seems not working. I would appreciate if anyone could suggest me a solution.

  • Tr `base_url + "/?s=ryhm" + String.fromCharCode(XXX) + "t"` where XXX is the char code of that character – MarshallOfSound Feb 18 '15 at 21:58
  • 3
    _location.href_ SHOULD have those non-ascii chars encoded into URL-safe entities, more specifically component entities; everything is correct. to turn them back into pretty text, use `decodeURIComponent(str)`. – dandavis Feb 18 '15 at 22:11
  • @MarshallOfSound the actual url is not hardcoded like above. I just presented this way to make it understandable. search keys are dynamic so that i cant change the character format. – user1109722 Feb 19 '15 at 07:22
  • Did you try using the `escape()` function? – ArinCool Feb 19 '15 at 07:30
  • @dandavis _location.href_ is the last command that navigates the page with encoded url how shall i decode it. _decodeURIComponent(url)_ doesnt work since url is not yet encoded. – user1109722 Feb 19 '15 at 07:43
  • there's nothing to fix on that page. if there's a problem, it's with the new page's JS or server page that the problem... if that new page uses JS, then the decodeURIComponent() function should turn that queryString part back into the orig text. – dandavis Feb 19 '15 at 22:30
  • @ArinCool escape causes "URIError: URI error" error – AmineG Sep 05 '16 at 11:12

0 Answers0