Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    175
    Thanks
    14
    Thanked 1 Time in 1 Post

    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

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •