View Full Version : How to target specific funtion within php page

03-09-2009, 06:10 PM

I am using this jquery ajax function
$.post("getpage.php",function(data){yada, yada});to return data from a mysql query and it works fine as long as the action destination only has one query. How do I modify this if the action destination ('getpage.php') containes several queries for different uses? Example, within the page, one function is written to insert into,and another is written to delete from.



03-09-2009, 09:02 PM
in any form that might call your function page include a hidden field. for the sake of the argument call it "what" (or add it as a parameter in your call). on your function page have a switch that uses $_GET['what'] for an argument.

so as part of a form:

<input type="hidden" name="what" value="function1" />

or as part of your call:

$.post("getpage.php?what=function1",function(data){yada, yada});

and as for getpage.php:

$what = $_GET['what'];
case "function1":
do something;
case "function2":
do something else;

all that said, i don't know how jquery fires that off... it probably won't like you using a get string in a post query... so you'll have to sort that detail. but the theory is there.