Reputation: 18639
I have accumulated a few AJAX scrips and they are a bit spread out within my directory structure.
Usually I just have the JavaScript call them and the scripts are named like "xyz_ajax.php"
I am trying to make things more organized. What is the best place to put these scripts within the source directory structure? And what is a decent naming convention? Or is my naming kind of ok?
Upvotes: 0
Views: 1104
Reputation: 9402
It is really personal preference, but certainly being consistent is going to help you out in the long run. It does somewhat matter if you are using a template/bootstrap/MVC etc framework as they tend to have their own best practices. I'm not exactly sure in your case what you mean by "source directory" but if it's public-facing, you may want to consider any issues if they are hit directly either by accident or maliciously, and in that case you may want to use a handler file, as described by @SamT.
Personally, I use an underscore to indicate a page or view fragment, but that's just my own style. It's also nice it that it groups the fragments from the main views as well as making them easier for me to identify.
Upvotes: 0
Reputation: 10620
Because this is a matter of taste, you can do it however you want. The way I have done it is create a single AJAX handler file, which is a front-facing web file that all AJAX requests are sent through. Based on the type of request, it will serve the right data. If you have many files, keep them in a single folder somewhere (with only ajax files, not with any include files) so you can keep that open for the public (as you need to in order for the browser to request/send information to and from these files).
Upvotes: 3