user1314159 user1314159 - 1 year ago 108
JSON Question

Concatinate HTML

I'm building my output text looping a JSON object using javaScript. Everything is working fine until I come to the part that I need to add an ID number to an image url. My images are stored in a database and I am using a ASHX handler to load the image however what I end up with is not exactly what I need.

My code that I need to end up with is


but what I get is
. Single quotes around the ID.

I know it is the syntax of

What I have tried is

myOutput += "<img src ='~/ImageHandler.ashx?id='" + ID + class='person-image'></img>"

and every combination that does not work.

If I remember correctly I need some combination of triple single quote or double quotes something or some combination of the both.
is an integer that is being read from a JSON object.

Thanks in advance

Answer Source

You can add double quotes using the escape character \

myOutput += "<img src=\"~/ImageHandler.ashx?id="  + ID  + "\" class=\"person-image\"></img>" 

This will append

<img src="~/ImageHandler.ashx?id=35" class="person-image"></img>