Ajax Organization Best Practices

I have a PHP based webpage. Using Ajax, I call the PHP routines. Is it better to keep each routine in a separate file. Or it would be better to save them all in one file and split the file using the $ _GET variable.

Example:
if($_GET['AjaxFunction'] == 1) {
...
} elseif($_GET['AjaxFunction'] == 2) {
...
} elseif($_GET['AjaxFunction'] == 3) {
...
}

+3
source share
2 answers

If the methods have nothing to do with each other, then my voice will be to have a separate file for each of them.

If the methods are subtle variations of each other, then it makes sense to have one file, which then looks at the query string or message form data.

. " [file | method | type | whatever]".

+2

, , . , Create, Edit, Delete Messages, Messages.php.

/messages.php?a=create       // Create new message
/messages.php?a=edit&p=12    // Edit message #12
/messages.php?a=delete&p=12  // Delete message #12
0

Source: https://habr.com/ru/post/1727121/


All Articles