1

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

1 Answer 1

4
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
Sign up to request clarification or add additional context in comments.

1 Comment

@spektom If you'll send the content using GET method then encodeURIComponent is enough and these hacks are not needed.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.