I'm developing an HTML page which has multiple AJAX requests using JQuery.
I'm using the POST
method and each request I make is to the same file, let's call this file X.
File X has a non static functionality, meaning that if I want to call function Y from file X then I have to somehow signify to file X that I want it to only run function Y and return this value.
My server language is PHP and I will give an example of the situation below.
$.ajax({
url : "X.php",
data : {
function_to_call: "Y"
},
type : "POST",
success: function(data){
alert(data)
},
});
The problem is that I keep adding new functions to file X. I do this by simply adding different values in the function_to_call
field and then simply using if statements to check the value of function_to_call
and then running this function or code. I have added many functions to file X and now file X is to large and hard to organize and debug.
What are my other options to solve this problem and what are the benefits and disadvantages of these options?