I am working with a JSON object that includes various messages to be displayed on a webpage using Javascript. This JSON file is located in a separate directory and I have full control over it, being loaded asynchronously.
There are specific cases where different messages need to be shown, some of which contain dynamic data readily available within the function. To integrate this dynamic data into the string, I currently use plus signs for concatenation.
{
"text": {
"successMsg": "<p class=\"success\">This is the success message. Variable is \" + dynamicData + \"<\/p> "
}
}
//Pseudocode
function displayMsg() {
var dynamicData = 'some data'
if (foo) {
//code to display the JSON text
}
}
However, when I attempt to showcase the message on the page, the variable is parsed as a string instead of displaying its actual value. Even though the variable holds a value at that moment, on the webpage it just shows the text dyanamicData
literally.
Your assistance on this matter would be greatly valued.
Thank you