Search code examples
ajaxdjangojsondajaxicedajax

Where to create html? Server or client side?


I am using dajax for ajax in my django app. After getting some data from database I create list of <li> elements in my python ajax.py and assign it with dajax to inner html of some container. Like this:

@dajaxice_register
def get_transactions(request):
    dajax = Dajax()
    transactions = get_transactions()
    dajax.assign('#transactions', 'innerHTML', ''.join(transactions))
    return dajax.json()

What is considered best practice? Returning html from server or returning json and then creating html in script?


Solution

  • I would return JSON from the server and bind that to the DOM using JavaScript. That way you're keeping concerns separate, and also returning the minimum amount of data from the server.