M
M
Mors Clamor2020-03-04 20:45:55
Yii
Mors Clamor, 2020-03-04 20:45:55

Is it OK to load HTML via AJAX?

Hello! There is a site, it has a system of posts, when loading a page with posts, they are loaded statically, that is, they are formed by PHP, I have implemented such a thing that when you click on the "post" button, the post immediately appears in this list, for this I store it html template and dynamically add it to the top of the list. There can be a lot of such things for which templates would be needed, and it seems to me incorrect to store all of them in the same file as the main page. I use yii2, there is an idea to scatter all this among widgets, but what about dynamic addition? Forward html?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
McBernar, 2020-03-04
@66demon666

Maybe the time has come when you need to completely separate the front and back and connect them via api?
It seems that your approach is quite normal, albeit strange. You can reduce template fetching time by simply putting it as a separate file in your project file structure and fetching it directly by getom, bypassing yii rendering.
But damn, this batch of monolith and js-render will tire you out.

V
Vladimir Korotenko, 2020-03-04
@firedragon

What's wrong?
For example, ASPX uses this technology, they send pieces of html when the page is redrawn. Another issue is that it complicates your code.
In general, there is no need for fanaticism.

A
Anton Shamanov, 2020-03-04
@SilenceOfWinter

this is contrary to the principle of separating data from presentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question