I have a JSON object containing few messages that I show on a webpage using Javascript.The JSON file is in a different directory and I have full control of it and loaded asynchronously.
There are few scenarios where I have to display different messages and some of them contain dynamic data, which are readily available inside the function. I need to include these dynamic data inside the string, which I have added using plus signs as below.
{
"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
}
}
When I display the message on the page, the variable just parses as a string. The variable contains a value at this point but on the webpage it just displays the text dyanamicData
as a string.
Any help is greatly appreciated.
Thanks