aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes JSON and HTML combined? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JSON and HTML combined?" Watch "JSON and HTML combined?" New topic
Author

JSON and HTML combined?

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Odd subject, but can't think of a better description. I have a series of forms that are submitted to the server via jQuery's Form plugin. That plugin requires a dataType be specified so it knows how to pre-process the response. In a lot of cases I simply return JSON that has a specific structure containing errors messages (if any) and usually a JSON'ified object that I can use in my client side code.

I have a somewhat special case in that I still need the JSON data, but I part of the post-processing requires me to build quite a bit of HTML. I'd rather just send the HTML with the response and load it into a container. I know that I can put the HTML in JSON



What I'm wondering is if I'm missing something simpler or better?


GenRocket - Experts at Building Test Data
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Probably not, although I'll be interested in hearing what you come up with--I had to do something similar and used FreeMarker to generate the embedded HTML and just left it at that. Never had to do it since then, either.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thanks David. I ended up just including the HTML in the JSON message. It was pretty easy, using Grails/Groovy to render the template appropriately. I'll post a link here after I've blogged about it.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

http://blog.greggbolinger.com/delivering-html-with-json-using-grails
 
wood burning stoves
 
subject: JSON and HTML combined?