Home >Backend Development >PHP Tutorial >javascript - When working on a project, should an ajax request correspond to a php file or should the php code be written in a file?

javascript - When working on a project, should an ajax request correspond to a php file or should the php code be written in a file?

WBOY
WBOYOriginal
2016-07-06 13:52:19946browse

If written separately, there will be a lot of php files and it will be messy. How should they be classified if they are written together?
How to handle the responses to different requests more efficiently when multiple ajax files correspond to one php file?

Reply content:

If written separately, there will be a lot of php files and it will be messy. How should they be classified if they are written together?
How to handle the responses to different requests more efficiently when multiple ajax files correspond to one php file?

It should be classified according to business classification rather than requests. For example, requests for User include requesting User information, modifying User information, etc. Since these requests are closely related to User, you can put these processing logic in one php file.

It is true that an ajax request can be a PHP. Even if it is written like this, there is no logical error; I am just accustomed to using another PHP to proxy all requests such as gateway; in this way, the front end only needs one address prefix, and the specific operation is hung here The prefix makes it easier to manage the program during later maintenance and development; in addition, this method is more suitable for server topology management, such as reverse proxy or load balancing;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn