I am doing an AJAX call and in the AJAX handler code (PHP side) I have to return a string containing the currency symbol. I have € to begin with in the PHP side, which I try to encode using html_entity_decode() but I am getting € when I alert the response in the javascript part.
I did html_entity_decode() of the value before returning the AJAX response in PHP –
$currency = "€"; //I am getting this from somewhere so I cannot change it.
echo json_encode(array("message" => htmlentity_decode($currency)));
But still it shows € when I alert using javascript.
Even when I look at the firebug console, it shows €.
I also checked that in non-AJAX case, for a normal PHP page, if I echo the following, I get € as expected –
$currency = "€";
htmlentity_decode($currency);
So, What am I missing here. Do I need to set some character related stuff using header()? I tried this –
header("Content-Type: charset=UTF-8;");
I also checked Html entities like € is not converted to its symbol in CSV conversion
Update
Note: I tried setting $currency = “€” but that sets the “message” attribute of the response null. The response in the firebug console output shows this –
{"message":null}
Update 2
I use jQuery.
What I do with the response?
I just display the response in a confirmation message like this –
if(confirm(res.message)){alert("confirmed")}. //this renders html entities (€), I want this to render €
I checked that if I append the response to something in the UI, the Euro symbol € appears – $('.jqModal').append(res.message);
I checked that by not making any changes in PHP side and explicitly decoding the HTML entities in the javascript side, after receiving response, the problem gets fixed. I added this javascript function
html_entity_decode()(phpjs.org/functions/html_entity_decode) and called it before alerting the response, but that too did not work (then I added support for Euro in that function) and now it works..