2

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.

Stephane
  • 1,613
  • 5
  • 20
  • 40

2 Answers2

1

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.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

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
});
ZZ Coder
  • 74,484
  • 29
  • 137
  • 169