I perform an AJAX request to a PHP script in JavaScript and by using the jQuery library.
Here is my command which performs the AJAX request :
$.ajax({
async: "false",
cache: "false",
data: {login: strLogin, password: strPassword},
datatype: "text",
error: connexionAjaxError,
success: connexionAjaxSuccess,
type: "POST",
url: "./Connexion"
});
".Connexion" is a URL redirection to my PHP script.
connexionAjaxError is a JavaScript function inevitably executed as soon as the HTTP response is received.
The reason : My PHP script results to a text/plain page with HTTP status code equal to 500.
Here is the most relevant part of my PHP script :
header("HTTP/1.0 500 Internal Server Error;
Content-type: text/plain;
charset=ISO-8859-1");
echo "été";
Here is the signature of the connexionAjaxError callback function :
function connexionAjaxError(jqXHR, textStatus, errorThrown)
My PHP results to the string "été".
My PHP internal encoding is ISO-8859-1 so the result string is encoded [e9 74 e9] in hexadecimal notation.
But jqXHR.responseText in the connexionAjaxError callback function contains a 1-character string.
I have used the charCodeAt method of the JavaScript String object to get the unicode (UTF-8 ?) code for the character.
The character is encoded 65535 in decimal notation equivalent to [ff ff] in hexadecimal notation.
I do not understand why jqXHR.responseText does not contain the 3-character string "été".
I am not an expert in JavaScript but I suppose jqXHR.responseText can only contains a string encoded in UTF-8.
So the string "été" in jqXHR.responseText would be encoded [c3a9 74 c3a9] in hexadecimal notation.
I have retrieve the UTF-8 code for the character "é" from the following web site : http://www.utf8-chartable.de/