How to run multiple ajax calls on one page

前端 未结 3 1804
暗喜
暗喜 2021-01-22 22:01

If I\'m making an \'ajaxified\' user interface with many ajax calls for creating, renaming, deleting various things on my page - what is the best way to handle all those \"code

相关标签:
3条回答
  • 2021-01-22 23:02

    Sure, what you are doing now is a much better aproach. Just have one file that controlls all actions. I usually use a switch statement on command to keep everything nice and clean.

    switch($_GET[command) 
    { 
      case 'insert' : do insert stuff; break;
      case 'delete' : do delete stuff; break;
    }
    
    0 讨论(0)
  • 2021-01-22 23:05

    Yes, that is better. There is nothing wrong with lots of files, however you should be striving to keep related functionality together--high cohesion.

    But don't go overboard and let the one php file handle more than just Candy. If you start to find code duplication amongst your php files, start subclassing.

    0 讨论(0)
  • 2021-01-22 23:07

    Assuming that you are handling security issues on the server side, I don't see a problem with your method. The PHP file has to make sure that the requester has privilege to execute the command. You wouldn't want an user deleting all of your records...

    0 讨论(0)
提交回复
热议问题