T
T
Toopie2018-10-19 20:26:12
IT education
Toopie, 2018-10-19 20:26:12

How do you properly separate the back-end from the front-end?

Hello.
I always wrote in PHP, then switched to a lesser known language, also for server development, but oh well.
Now I am training to write both front and back.
Now to the problems:
Almost everywhere it is shown that if, for example, PHP is taken, then it can be embedded directly into HTML, but it seems to me that this approach is not entirely correct. I wrote a test blog in such a way that jQuery sent a request to PHP, and PHP, in turn, gave JSON, and even JS itself set a cookie for the user.
So, in fact, which method is still correct - write PHP directly in HTML, or, after all, use PHP as the site's API and send a request to it from JS?
I would like to learn how to combine right away. Thank you for your attention =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
stul5tul, 2018-10-19
@Toopie

Almost everywhere it is shown that if, for example, we take PHP, then it can be embedded directly into HTML

You never know what is "almost everywhere shown."
Almost all code examples on the Internet are greatly simplified for better understanding.
These examples should be used wisely.
Typical:
Real code contains a bunch of checks for possible errors.
If you use such a full-fledged working code as an example, then neophytes simply will not understand where the main idea is, what exactly the author wanted to say. All sorts of checks that are at every step in real code will simply scatter their attention and distract them from the main thing.
Therefore, almost all examples do not have these error checks.
But this does not mean that in reality these checks do not need to be done.
There is no absolutely correct method.
If you write a full-fledged API for a small project, you will significantly delay the time and cost of your work. And this is a full-fledged API and will not be needed.
Well, vice versa. Writing a complex project, interfering in one JS/PHP/HTML file, will simply be inconvenient to maintain and develop as the project grows.
Choosing the right solution in a particular case is just an indicator of your qualifications.
Learn all the methods .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question