First, overview:
- Processing response data rendering can use the template engine (which is actually an API to make it easier to render data into HTML)
- There are many template engines available on the market, so you can refer to
- It is recommended to use Arttemplate, It uses scoped pre-declared technology to optimize template rendering speed, while supporting NodeJS and browsers.
Second, the template engine steps:
① Select a template engine to download the template engine files
② introduced into the page
③ Prepare a template
④ Prepare a data
⑤ provides a function to integrate templates and data to render the resulting HTML through the template engine's JS
⑥ setting the HTML of the rendered result to the innerHTML of the default element
Iii. reasons for template writing to script
- If you write to the JS variable, maintenance is inconvenient, cannot wrap, no coloring
- Written to the Script tab, innerHTML is not displayed on the interface
- Note: If type is not text/javascript in the script tag, the contents of the tag will not be installed JS file execution
Iv. reference: JavaScript template engine Instance application
Using the template engine in Ajax