I’m creating a website which will require much AJAX functionality. At the moment I’m creating multiple PHP files each containing the processing for each AJAX ‘function’. I just realised an alternative would be to create an uber-PHP file that all AJAX calls would request, passing a specific “cmd” parameter specifying what functionality to execute server-side.
Are there dis/advantages to either approach? How is it commonly done?
I’m creating a website which will require much AJAX functionality. At the moment I’m
Share
There are some consolidation opportunities with a big AJAX handler/dispatcher script. You can probe for
HTTP_X_REQUESTED_WITHin a central place. And if you need proper authorization for some functions, do it for all requests alike.And obviously you can also unify the output format/handling. Instead of replicating the header response, you need to write that only once.
But don’t bother with assessing the performance theory behind this or that approach. Unless you need a very simple callback feature (e.g. dictionary checks) which might benefit from a separate script, handle it with one big ajax script. Most often a central script would provide the security and maintenance advantage.