I have a small sistemka accounting elephants, elephants blue, red, their addresses, names, and so on. The user can watch lists of elephants by city, by color, edit it all. In general, tabular data. At the moment, the html-code is generated by a php-script by POST requests, but for the sake of practice I transfer to ajax.

How smarter to form a table? I guess these options :

1) generate html on the server, then ajax {dataType: html} and output to the page;

2) ajax {dataType: json}, we receive, we parse, by means of js we form the table. But then there will be porridge in js, although nobody is looking there.

Additional: no load, no matter where it will be performed.

  • Templization is better to keep in one place. If you generate everything on a server, then it is also easier to give HTML to AJAX. If you want a combined version, look at the template engines that work both on the server and on the client (for example, mustache) - Dmitriy Simushev
  • I would choose the second option. It seems to me more flexible. - A1essandro
  • Nowadays, with the reactor and the angulyar, it is better to get data and template it on the client. - Vasily Barbashev

1 answer 1

Theory

It is always better to drive only data between the server and the client.
All that you can do on the client → do on the client.
If time and desire allows, I would really be using MVC .
It will be easier to maintain later, and no one has canceled new knowledge and skills.

In fact, even on vanilla js there will be no porridge if you approach the matter correctly, for example

Practice

  1. Your project is on fire → we write a shit code, as in your first version
  2. The project does not burn → do as described in theory
  • So most modern cms do the first option. or rather everything I know about. - Jean-Claude