I have this simple idea to convert my \n
line breaks from my ajax JSON call to <br>
so that it would properly display my data.
I tried many different ways to perform the conversion but I keep getting an error saying:
Uncaught TypeError: data.replace is not a function
The issue seems to be the way I'm making this call:
var incident = incident.replace(/\n/g, "<br />");
From what I see on the forums here this is how we're suppose to use .replace
but I'm not understading why it doesn't like it.
I tried doing this as well:
"<td colspan='3'>"+incident.Impact.replace(/\n/g, "<br />")+"</td>"+
This works but if the field is empty it returns with an error stating that it cannot read .replace
of undefined. Would anyone have any ideas?
Full code:
$.ajax({
url: this.basePath() + '/GDI_PROD_Incidents?$filter=ÉtatValue%20ne%20%27Fermé%27&$orderby=PrioritéValue desc',
dataType: 'json',
cache: false,
success: function (data) {
$.each(data.d.results, function (index, incident) {
var incident = incident.replace(/\n/g, "<br />");
$('body').append(
"<table border='1' width='800' >"+
"<tr bgcolor='#9aff99' align='center'>"+
"<td width='800px' colspan='4'><strong>Transfert de connaissances</strong></td>"+
"</tr>" +
"<tr bgcolor='#fff'>"+
"<td width='165'>Billet:</td>"+
"<td>"+incident.Incident+"</td>"+
"<td width='165'>Priorité:</td>"+
"<td>"+incident.PrioritéValue+"</td>"+
"</tr>"+
"<tr bgcolor='#fff'>"+
"<td width='165'>Description:</td>"+
"<td colspan='3'>"+incident.Description+"</td>"+
"</tr>"+
"<tr bgcolor='#fff'>"+
"<td colspan='4' width='800px' bgcolor='#9aff99' align='center'>Détails</td>"+
"</tr>"+
"<tr bgcolor='#fff'>"+
"<td width='165'>Impact:</td>"+
"<td colspan='3'>"+incident.Impact+"</td>"+
"</tr>"+
"<tr bgcolor='#fff'>"+
"<td width='165'>Dépannage</td>"+
"<td colspan='3'>"+incident.Dépanage+"</td>"+
"</tr>"+
"<tr bgcolor='#fff'>"+
"<td colspan='4' width='800px' bgcolor='#9aff99' align='center'>Suivi</td>"+
"</tr>"+
"<tr bgcolor='#fff'>"+
"<td width='165'>Prochain Suivi:</td>"+
"<td colspan='3'>"+incident.Suivi+"</td>"+
"</tr>"+
"<tr bgcolor='#fff'>"+
"<td width='165'>Ressource:</td>"+
"<td colspan='3'>"+incident.Ressources+"</td>"+
"</tr>"+
"<tr bgcolor='#fff'>"+
"<td width='165'>Prime:</td>"+
"<td colspan='3'>"+incident.ResponsableValue+"</td>"+
"</tr>"+
"</table>"+
"<br><br>");
})
}
});
tags. – JJJ Jan 19 '16 at 15:06