I recently changed some of my pages that will be displayed via ajax, and I have some confusion as to why the utf8 encoding now displays a question mark inside the field, whereas it was not before.
As an example. The oringal page had index.php. charset was explicitly installed in utf8 and is located in <head> . Then I used php to query the database
Heres is the original page of index.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Title here</title> </head> <body class='body_bgcolor' > <div id="main_container"> <?php Data displayed via php was simply a select statement that output the HTML. ?> </div>
However, when I made the change to add a menu that populated "main_container" via ajax, all utf8 encodings stopped working. Here's the new code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Title here</title> </head> <body class='body_bgcolor' > <a href="#" onclick="display_html('about_us');"> About Us </a> <div id="main_container"></div>
The display_html () function calls a javascript page that uses the jquery ajax call to retrieve the html stored inside the php page and then puts the html inside the div with the id "main_container". I install charset in jquery as utf8 like:
$.ajax({ async: false, type: "GET", url: url, contentType: "charset=utf-8", success: function(data) { $("#main_container").html(data); } });
What am I doing wrong?
jquery ajax utf-8
Ronedog
source share