user1314159 user1314159 - 1 year ago 142
JSON Question

Concatenate HTML

I'm building my output text looping a JSON object using JavaScript. Everything is working fine until I come to the part where I need to add an ID number to an image URL. My images are stored in a database and I am using an 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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download