0

Possible Duplicate:
using jquery $.ajax to call a PHP function

I need to call a specific php function within my php file. Is there any way to point to that function with jquery ajax call instead of calling the whole URL?

Community
  • 1
  • 1
Adam Boostani
  • 5,409
  • 7
  • 36
  • 44

3 Answers3

1

Without a PHP framework, here are some ways to do it:

1 - Put the function in its own file.

2 - Put a wrapper function in its own file: all it does is #require your file, then call your desired function.

3 - Create one file that handles ajax (that'll be the entry point). Then pass a choice of functions using GET. Something like ajax_handler.php?fn=MyFunction

Robert Martin
  • 16,231
  • 15
  • 53
  • 87
0

Nope. You may need to factor out the function. Place it in a separate file and have it echo a JSON response or whatever you see fit when it is being called via Ajax

Rolando Cruz
  • 2,764
  • 1
  • 14
  • 24
0

You can try if the following StackOverflow question answers your query:

jQuery: Return data after ajax call success

using jquery $.ajax to call a PHP function

Also, some more information on what exactly and why do you wish to get such a functionality might be useful.

Community
  • 1
  • 1
gagneet
  • 33,361
  • 29
  • 75
  • 102