Take the 2-minute tour ×

I could create two ajax requests, but I'm wondering if there is an easy way to make one request send the HTML to one div and the json to a jquery template. I've grouped different JSON requests together in the past, but this involves tagged HTML.

Regex and string ops in javascript come to mind, but that could get slow on large datasets.

I would rather not have the server "JSON" the HTML into one element, which will involve a lot of escaping and time.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

You could have the response be JSON, with a HTML field (html), and another nested object (object):

    "html": "<a href...",
    "object": {}

Of course, you can use better names.

share|improve this answer
Thanks. Will I have any issues with character escaping in the future? That is my main concern... –  Len Jan 7 '12 at 3:51
@Len: If you're using json_encode, for example (in PHP) or a similar escaping function then no. –  U2744 SNOWFLAKE Jan 7 '12 at 3:58
@minitech is right. Also, the HTML should be raw HTML (hopefully trusted). –  Matthew Flaschen Jan 7 '12 at 4:21

Your Answer


