I have a jQuery Ajax call to my server to retrieve some HTML for a section on my page based on some user activity with my site. I'm finding I need in addition to the rendered HTML from the server some JSON data. What's best way to return to the client rendered HTML and JSON data? I'm thinking there are 3 different options:
make a second call to the server for the JSON data. This involves a second round trip. I can string multiple ajax calls using:
$when(call_1, call_2).done(function(results_1, results_2){...}))
include a script block in the rendered html that is called once the rendered html is added to the dom:
... rendered html output ... $(document).ready(function () { alert('data here'); });somehow embed rendered html into json returned from call then have calling JS function separate the rendered html from JSON and update DOM accordingly. This option just smells bad.
I'm leaning to option 1 even though it's an additional server hit because it seems like a better approach. Which approach is better in your opinion? Is there another way I've not thought of?
Thanks