Len
Len

Reputation: 542

JSON and HTML in one request?

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.

Upvotes: 2

Views: 313

Answers (1)

Matthew Flaschen
Matthew Flaschen

Reputation: 284826

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.

Upvotes: 8

Related Questions