I need to send a text content of an HTML node over Ajax request, but first convert it to UTF-8. Is that possible?
Thanks!
asked Jul 18, 2011 at 19:24
Michael Spector
37k7 gold badges67 silver badges90 bronze badges
1 Answer 1
function encode_utf8( s )
{
return unescape( encodeURIComponent( s ) );
}
function decode_utf8( s )
{
return decodeURIComponent( escape( s ) );
}
from http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html
use it like this...
encode_utf8(document.getElementById(id).textContent);
answered Jul 18, 2011 at 19:31
Greg Guida
7,5004 gold badges32 silver badges40 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Karolis
@spektom If you'll send the content using GET method then
encodeURIComponent is enough and these hacks are not needed.lang-js