Consider an AJAX request that fetches HTML text from a database:
xmlhttp.open("GET","get_html.php",true);
The response to this request could possibly contain special characters (entered through a WYSIWYG editor) which will get rendered as "junk" characters as there is no natural way for the response to know the encoding. As a result the output fetched by the response needs to be encoded. One of the ways of getting HTML text rendered correctly in an AJAX response is by encoding it using utf8_encode() and then using html_entity_decode() as follows:
//code to fetch response data from db into a var, say $db_data
$utf8_encoded_char = utf8_encode($db_data);
$html_text = html_entity_decode($utf8_encoded_char);
$html_text = html_entity_decode($utf8_encoded_char);
No comments:
Post a Comment