I’m using this code to get some html content from a php page:
$.ajax({
url:server+'/getMessage/40',
cache: false,
success: function(res) {
var text = res.responseText;
$('#result').html(res);
}
});
The text is retrieved from the db.
The php file looks like this:
$app->get('/app/get/getMessage/:Id',function ($Id='') use ($app) {
$msgElements = 'Title,Body';
$msgFe = $conn->query("SELECT $msgElements FROM messages WHERE Id='".$Id."'");
$fields = explode(',',$msgElements);
while($msgData = $conn->extract($msgFe)){
foreach($fields as $field) {
$arr->$field = $msgData->$field;
}
}
$ele=' <div class="modal-header">
<h1>'.$arr->Title.'</hi>
</div>
<div class="modal-body">
'.$arr->Body.'
</div>
<div class="modal-footer">
</div>
';
echo $ele;
});
If I place the browser the the location of the php page, with the proper GET instructions, I get the text without any problem. However, if I retrieve the text with the above ajax function, it shows the ?s…
From my tests (and other threads here on SO) I’m assuming the problem relies somewhere in the ajax function… Any help?
PS I’ve noticed that if I try to use json_encode() on the text that contains characters that are not properly visualized the result is null. I hope i helps!
You have to
utf8_encode()your values from your database because the resulting value is not utf8 encoded as you said.