I'm struggling getting a pound sign (£) back from my Ajax call.
This is the jQuery call I have
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_GB/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
$.post('ajax.php?vno=' + new Date().getTime(), {
action: 'submit'
}, function(res){
if (res.status) {
alert(res.post);
FB.api('/me/feed', 'post', { message: res.post },function(){});
}
},'json');
In my PHP script, I pass back html_entity_decode("£");
but the alert shows £
.
If I change my PHP code to html_entity_decode("£");
the alert box shows nothing
How can I get the alert to show £
?
Javascript alerts don't interpret HTML entities (see the answer to that question for an example of how to decode the entity before alerting it.) If you're just testing with the alert something that you're actually going to insert into the HTML web page, then if you see £
, then your final code should work fine.
But there's no great need to use an entity, anyway. If the character encoding for your Ajax return and your web page are set right (e.g. both UTF-8), then just returning '£' should work in the alert and the page. Trust me, I'm British. We have a £ key on our keyboards and it pretty much just works as a character on the modern web :)