JQuery to PHP function and back Ajaxed

Posted by Xaris on Stack Overflow See other posts from Stack Overflow or by Xaris
Published on 2010-06-17T13:11:57Z Indexed on 2010/06/17 13:13 UTC
Read the original article Hit count: 192

Filed under:
|
|

Hi all, i have a set of php function that i want to call on different events mostly onclick with jquery async (ajax). The first function is called on load

      $(document).ready(function()
        {
            $("#div2").hide('slow');
            $("#div1").empty().html('<img src="ajax-loader.gif" />');
            $.ajax(
            {
                type: "POST",
                url: "WebFunctions.php",
                data: {'func':'1'},
                success: function(html)
                {
                    $("#div1").show('slow').html(html)
                }
            });

The Data: {'func':'1'} --> is a switch statement on the php side

switch($_POST['func'])
{
  case '1':
    getParents();
    break;
  case '2':
    getChilds(params);
    break;
  case '3':
    getChildObjects(params);
    break;
  default:
}

"This functions are calls to a soap server" <-- irrelevant.

So when that function finishes i get an array which contains IDs and Names. I echo the names but i want the ID for reference so when i click on the echoed name i can call an other php function with parameter the ID of the name...

How do i get rid of the switch statement?? How do i call properly php functions and pass params to it??? How can i save this IDs so when i click on an item with that id an other php function is called??

Plz feel free to ask any question, any answer is welcome :)

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery