First of all, to find out what encoding is used for requests, install something like Firebug and check the Content-Type header of your request / response. It will look something like this: application / json; encoding = ... '. This should be charset=utf-8 in your case.
My guess is why this worked when submitting the form, probably due to x-www-form-urlencoded - non-alphanumeric characters are additionally encoded on the client side and decoded again on the server, which is the difference in sending data directly.
This means that somewhere there is an incorrect encoding at work. PHP treats your strings agnostically by its default encoding, so I would prefer to exclude it as the source of the error. jQuery.post also uses UTF-8 by default ... so my suspect is the filename variable. Are you sure this is in UTF-8? Where and how do you extract it?
You should probably also make sure that the actual HTML page is also sent as UTF-8, and not, say, iso-8859-1. Take a look at the article for a detailed explanation of how to do this.
source share