Issue in display special characters fetched from AJAX call

Using AJAX, I fetch data, and I have to dynamically append that data as rows in html table.

There are some special characters which are not being displayed in table. Though, they are currently shown if printed using 'alert' or with html tag.

Here is my code:

var mytext = '';
var color = "black";
for (t in events) {
    mytext += '<tr style="color:'+color+';">';
    mytext += '<td style="color:blue;"> <a onclick=\'load_iframe(' + events[t].event_id + ',"' + events[t].signature  +'");\'>';
    mytext += $('<div/>').html(events[t].signature).html();
    mytext += '</a> </td>';
    mytext += '<td>' + events[t].start_time + '</td>';
    mytext += '<td>' + events[t].end_time + '</td>';
    mytext += '</tr>';
}
$('#events_table > tbody:last').append(mytext);

The value of events[t].signature being shown in table is "venci\u00f3_humano". If I print it using html/alert it shows correctly. : venci?_humano

Can anybody please tell me how to fix this?

Thanks alot!

Answers 1

  • The following code working fine.

    var mytext = '';
    var color = "black";
    mytext += '<tr style="color:grey;">';
    mytext += '<td style="color:blue;"> <a onclick=\'load_iframe(7 ,"venci\u00f3_humano");\'>';
    mytext += $('<div/>').html('venci\u00f3_humano').text();
    mytext += '</a> </td>';
    mytext += '</tr>';
    $('#events_table').append(mytext);
    

    jsfiddle


Related Articles