accent ajax encoding issue
10,076
Solution 1
This is because you are displaying UTF-8 encoding of é (0xc3, 0xa9) as Latin-1. So the search_word was encoded as UTF-8 when it posted to PHP.
Try this,
$.ajaxSetup({
scriptCharset: "iso-8859-1",
cache: false
});
Solution 2
That is because the default return type of an AJAX call is UTF-8. Try
utf8_encode($output);
in your ajax snippet. Alternatively, you can change the encoding of the AJAX request as described here.
Author by
Stephane
After 12 years of being an employee, I"ve started my own tech support company. Most of my revenue is from web applications, and I have a huge exciting project on it's way: http://thehapzies.com <-- not set up yet. Beta registration coming soon.
Updated on June 04, 2022Comments
-
Stephane almost 2 years
Source file has:
header('Content-type: text/html; charset=iso8859-1');
Source ajax (jQuery) script is:
$(document).ready(function() { $.ajaxSetup({ cache: false }); $("#searchfield").keyup(function(){ $("#insert_search") .load('ajax/searchobjects.php', {search_word: $("#searchfield").val()}, function(){ }); }); });
Destination file:
header('Content-type: text/html; charset=iso8859-1'); echo $_POST['search_word'];
Data sent:
é
Result is:
é
All files:
Western (ISO Latin 1) (using TextWrangler)
Funny thing: I can insert records into MySQL just fine with accents.