Is it possible to call a function using jQuery.ajax

Hi, can i ask some help,i have some problem,… Is it possible to call a function using the jquery.ajax?

Example inside of this file “myPHPfunction.php”



    function deleteaccount(param1,param2){
         ..................
         some statment here....
   }


    function addingccount(param1,param2){
         ..................
         some statment here....
   }


  ect......
  

Now if i have a form to be submitted to the “myPHPfunction.php” via ajax
and i want to call the addingaccount function, how can i call that function name via ajax Is this possible?

this is the code but i am stuck here.


   var mydata = $('#myformIDX').serialize();
       $.ajax({
          type:'post',
          url: 'myPHPfunction.php',
         data: mydata
         success: function(dtx){
                 alert(dtx);
       }
   });
   

Please help me on this.

Thank you in advance.

Hi jemz,

You normally pass a variable to your server-side script, using the data property.

$.ajax({
  type: 'post',
  url: 'myPHPfunction.php',
  data: {registration: "success", name: "Pullo", email: "pullo@pullo.de"}
});

Then, on the server side, you can retrieve it from the _POST variable and act accordingly:

$regstration = $_POST['registration'];
$name= $_POST['name'];
$email= $_POST['email'];

if ($registration == "success"){
 addAccount($name, $email);
}

Hi pullo thank you for the reply…so this code


$regstration = $_POST['registration'];
$name= $_POST['name'];
$email= $_POST['email'];

if ($registration == "success"){
 addAccount($name, $email);
}

Is on top of my function name “addaccount” ?

so the structure would be something like this inside in “myPHPfunction”


 $regstration = $_POST['registration'];
$name= $_POST['name'];
$email= $_POST['email'];

if ($registration == "success"){
 addAccount($name, $email);
}

function addAccount($name,$email){
   ...............
 .................
} 


Yes, that’s right, although I would define the function before calling it.

Thank you pullo :slight_smile: