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?
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?
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;