Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-09-2009, 06:10 PM   PM User | #1
1andyw
Regular Coder

 
Join Date: Jul 2006
Posts: 171
Thanks: 13
Thanked 1 Time in 1 Post
1andyw is an unknown quantity at this point
How to target specific funtion within php page

Hi,

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.

Thanks,

Andy
1andyw is offline   Reply With Quote
Old 03-09-2009, 09:02 PM   PM User | #2
ohgod
Regular Coder

 
ohgod's Avatar
 
Join Date: Jun 2008
Location: Ohio
Posts: 579
Thanks: 6
Thanked 69 Times in 69 Posts
ohgod is on a distinguished road
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:
Code:
<form>
<input type="hidden" name="what" value="function1" />
</form>
or as part of your call:
Code:
$.post("getpage.php?what=function1",function(data){yada, yada});
and as for getpage.php:
PHP Code:
$what $_GET['what'];
switch(
$what){
case 
"function1":
do 
something;
break;
case 
"function2":
do 
something else;
break;


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.

Last edited by ohgod; 03-09-2009 at 09:05 PM..
ohgod is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:01 AM.


Advertisement
Log in to turn off these ads.