I am looking for information on this topic as described below. In particular, I'm looking for the “best-known method” or design pattern in which HTML is dynamically generated.
This is a very common task for me: Send something to the server via POST → get a list of results in JSON format → take this list from 0 to n results and show them, often as a list. This usually means creating the actual HTML in Javascript (jQuery) with something like:
HTMLResult = "<div id=.... " HTMLResult = HTMLResult + JSONDataElement HTMLResult = "</div>" ...
Then I add each element using jQuery, or collect them and replace the HTML of some container div.
I'm tired of doing this. This is a mistake, prone, ugly, inefficient, etc.
I would rather do something else OO. Perhaps the element will be defined in some way - it is in the div, span that it contains ... so that I can do something like this:
tempElement = new Element tempElement.text = JSONData.text ResultsList.addElement(tempElement)
I am looking for information on the best ways to do what I described. I prefer a minimal set of tools: HTML, CSS, jQuery.
(Also how to build HTML on a server, in this case Django)?
source share