-3

Possible Duplicate:
Call PHP Function using jQuery AJAX

I have a PHP file containing all functions created by me. I just want to know, how can I call a specific function through Ajax?

Community
  • 1
  • 1
Ajay
  • 43
  • 5
  • I'm not sure what you mean with this. You can only AJAX call a URL. You would need to have the functions at a separate URL or use some MVC framework to map them – Joe Doherty Jan 28 '13 at 11:01
  • If you have a different `URL` for each of the methods, you can call those urls to call the methods associated with them – Arun P Johny Jan 28 '13 at 11:02

3 Answers3

1

You could pass a get or post variable and use it to then using php call a specific function. WHat exactly are you trying to achieve ?

Jean-Georges
  • 658
  • 4
  • 12
0

send the function name through GET method to the php page and then execute _GET value using call_user_func

http://php.net/manual/en/function.call-user-func.php

Can Geliş
  • 1,454
  • 2
  • 10
  • 19
0

You could use call_user_func():

$name = $_POST['function'];

if (in_array($name, $allowed_functions)) {
    $result = call_user_func($name);
}

Although this reeks of bad design. Why do you need to do this?

Blender
  • 289,723
  • 53
  • 439
  • 496