Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  

AJAX Usage Question(s)

Recommended Posts

Posted · Original PosterOP

Hey everyone,


So I've only just begun to play around with AJAX and I'm hoping my understanding is too restrictive and that my assertion is incorrect:

Suppose you have a utilities PHP file that performs general server-side operations and that you want to call each independent function via AJAX. The problem I'm having is it doesn't seem like you can pick and choose what functions you want to call. Rather, you call the entire page and that page returns some value after running its operations. That said, it seems really silly to have a hundred PHP files with very tiny snippets instead of calling from one file with a hundred functions.


So supposing you have the file derp.php and want to call function addStuff($arrayOfThings), how would you carry this out?


(I've seen some hacks around this like passing in the name of the function as part of the parameters list but, again, that seems very silly)


I appreciate any help you can provide.

Link to post
Share on other sites

The php script can't magically figure out what function you want to call. The best way I can think of doing it is putting all your functions in 1 file and use a simple GET parameter like "derp.php?f=10" then in the php file have all your functions and at the end put a switch statement that translates the number in 'f' to a function (I wouldn't put the actual function names in the url).


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this