Keeping track of supporting php file for ajax functions

I been writing codes for roughly 2 years. I started by learning html, then css then php. I have been managing to write everything I need with these three script languages so far. I am now starting to get more experienced and realize that I also need to learn javascript or more precisely how to use the ajax method.

My question is how to keep track of all the supporting php files used in conjunction with the ajax functions? I have looked at numerous tutorial on javascript and ajax and all use a separate php file to perform the work to the server.

After a while I am realizing that I will probably have to create hundreds of php file given the scope of my website. what is the best way to organize these php files and what would be best naming practice to identify these files?

to JavaScript those scripts are simply URLs. Hence you could rephrase your question to “How do I keep track of all the supporting URLs?” which you could do like for website URLs, e.g. with a server-side framework.

It is not necessary to have separate PHP file for each request.
You can have one (or more) file with functions defined inside, where each function will be responsive for specific AJAX action.

ok, I think it would make sense to go about it the way you propose. What about naming the functions? any ideas on how I could come up with a naming system?

Can we get some idea of the types of ajax request and names that you are currently dealing with?

Hi Paul,

I don’t have any ajax at the moment. I have an extensive database management system controlling everything that goes around in an elder assisted living facility. Client, their care, appointments, building maintenance, fire safety, projects, tasks, schedules, inventory, asset conditions and the list goes on and on… I have got a pretty good start on the fire safety module but every time I need a refresh I have to reload the whole page so I figured it was time to start thinking about ajax requests. I stayed away from it as much as I could but at a point where it would be dumb not to bring javascript into the application even if it mean diving into learning a new script language.

I thought maybe I should just use the system I have with my php classes and methods and start a new similar system for JS? I just don’t know what I should do. What I hate the most about JS is how easy it is according to everyone who uses it lol. I been coding in php for almost two years and from my perspective it’s ten time more complicated than php if you ask me. I’m not a big fan of JS but I hope that will change in the future.

You may be interested to learn learn then that I consider JavaScript to be one of the most hostile development environments that are out there.

For example, when writing PHP you have at least some idea of the interpretor version that will be used, whereas with JavaScript we have little to no idea on the web browser that a user will be using when visiting. And even if browser sniffing (ugh!) were to occur, better techniques such as feature detection, polyfills, and setting hard limits (such as no IE6 allowed) result in easier maintenance and better development.

When it comes to AJAX, it’s a simple process of JavaScript making a request to the server (such as to a PHP script) where JavaScript then continues to process things until a response comes back from the server.

In terms of file names, it can help to keep the ajax-specific files in a separate directory structure, and I even find that naming them things like user-login.ajax.php to be handy too.

Oh, and good news - a guide to ajax with both vanilla JavaScript and jQuery examples was recently published here too.

thank you, I will certainly check it out

I usually use {action}{Subject} pattern, for example

addPost();
updateUserStatus();

and so on

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.