I'm developing a dashboard which can send certain POST requests to my http server. The POSTs are sent through Ajax and any http errors are being output to the client on a "console" (a modified <textarea>
).
Ajax call:
function download() {
var url = "/myApi/getData/2";
$.ajax({
type: "GET",
url: url,
data: "",
success: function (data) {
$(".error-log").html('');
window.open(url, '_blank');
},
error:function (xhr, ajaxOptions, thrownError) {
$(".error-log").html(xhr.getResponseHeader("Status"));
}
});
}
The backend looks like this:
$db = $this->getRow($id);
if(!$db) {
header('Status: No such row in database', true, 404);
exit;
}
The problem I'm having is when my message contains special characters, such as ä, Ä, ö, Ö
. Those characters are returned as %C3%A4
. I tried setting the charset
of the header but it didn't work:
header('Content-type: text/plain; charset=ISO-8859-1');
header('Content-type: text/plain; charset=UTF-8');
How can I return the correct characters? Everywhere I look people suggest changing the charset, but it doesn't seem to work.