twitter bootstrap - Javascript string concatenation -


i have problem string concatenation. making series of ajax calls , results building table, each element has bootstrap popover field. in field show additional details. here code:

...initiate ajax post ... ... other parameters... function(data){//function called on success         var popovercontent = 'sent: ';         popovercontent = popovercontent.concat(json.stringify(obj.value));         popovercontent = popovercontent.concat('\nreceived: ');         popovercontent = popovercontent.concat(json.stringify(data.error));         console.log(popovercontent);  ... other processing ... ...building table...  '<td> <a class="btn large primary" rel="popover" data-content='+popovercontent+' data-original-title="detailed description">'+outcome+'</a></td>'+ ...  ...rest of code ... 

now problem while in console popovercontent has data want display in form of string, in popover sent: gets displayed. if make popovercontent equal other concatenated part displays part, whole thing not. missing here?

instead of have before console.log call, can use += operator easier read (though not requirement), this:

var popovercontent = 'sent: '; popovercontent += json.stringify(obj.value); popovercontent += '\nreceived: '; popovercontent += json.stringify(data.error); 

the real problem, however, in actual html output. you're not surrounding results "s. in fact, need escaped well. like:

... '<td>' +   '<a class="btn large primary" rel="popover" data-content="' +       popovercontent.replace(/&/g, '&amp;').replace(/"/g, '&quot;')      .replace(/\n/g, '<br/>') +     '" data-original-title="detailed description">' +     outcome +   '</a>' + '</td> + ... 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -