accent ajax encoding issue
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/search开发者_如何学Pythonobjects.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.
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.
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
});
精彩评论