Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSON and HTML combined?

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic