proper way to construct HTML based on AJAX input

我的梦境 提交于 2019-12-05 13:12:54

What I've done before is let my server do the processing and code generation. Keeps the load off the client.

You could load partials (views) and return them, json encoded or otherwise. If you use json, make the HTML be "content" in your response object or something similar.

This way, there's no code duplication since you can use the same views. The trick becomes how to split them up.

Instead of constructing html strings, have you considered holding an array of javascript dom objects inside of javascript classes which hold your relational database data in them and then just cycling those around / building them with AJAX based on user interactions? This is how I maintain a photo gallery of nearly 500 photos (broken into sets) on one page with dynamic preloading (allowing the user to have a full size image instantly when they select it).

Also came across this 1999 feeling and settled for jQuery tmpl. It'll allow you to keep model and views separated and more time to concentrate on the business logic. You can define a template by using a script-tag of type text/x-jquery-tmpl anywhere within the documents body and use it by addressing it by its id.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!