After the client presses a button - a server side function must be executed and according the result different client side functions be executed..
To achive this I used AJAX and wrote this function :
function invoke_php(file_name, parameters){
parameters = typeof parameters !== 'undefined' ? parameters : '';
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
switch (xmlhttp.responseText) {
case "func1":
func1();
break;
case "func2":
func2();
break;
default:
default_func();
}
}
};
xmlhttp.open("POST", file_name+"?"+parameters, true);
xmlhttp.send();
}
Server side functionality is performed in separate php file, which returns the name of the function to run. the invoke_php function uses switch on the respone text and execute the suitable client-side function...
It feels like there is a better way to do this.... Any improvement suggestion will be appreciated..:)