I have a problem with my application made in PHP and javascript.
I have an ajax call to a function php that get values from database.
I retrieve many records with fields and inside it I have a field called description
with a value like this:
<p><strong>TEST IT</strong></p><p>non gras<span style="color: rgb(192, 145, 0);">sett</span>o </p>
After I encode the json, get it in javascript and print it. But the result is:
TEST+IT
non+grassetto++
My code is something like this:
AJAX call:
$.ajax({
url: site_url_database,
type: "GET",
async: true,
data: window.location.search,
dataType: "json",
timeout: 30000,
success: function(data) {
_.each(data.hotel, function(d, index_d) {
data.hotel[index_d].description = decodeURIComponent(d.description);
});
},
error: function(data) {
}
})
PHP function to get field description:
....
$hotel_array['description'] = urlencode($row->hotel_description);
....
//encode array to return
$hotel_array = json_encode($hotel_array);
echo($hotel_array);
After I print it in javascript (Backbone) but if I make a console.log()
I get this:
TEST+IT
non+grassetto++
How can I print it well?
Thanks
P.S. I can't change the method of working so I need an ajax call a function php and print it in Backbone/javascript I only need to encode and decode well
I have already tried in php:
$hotel_array['description'] = addslashes(htmlentities($row->hotel_description));
In javascript I have tried to use: https://raw.githubusercontent.com/kvz/phpjs/master/functions/url/urldecode.js