SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post 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"

    Code:
        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.

    Code:
       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.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi jemz,

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

    Code JavaScript:
    $.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:

    PHP Code:
    $regstration $_POST['registration'];
    $name$_POST['name'];
    $email$_POST['email'];

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


  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Hi jemz,

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

    Code JavaScript:
    $.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:

    PHP Code:
    $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

    PHP 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"
    PHP Code:
     $regstration $_POST['registration'];
    $name$_POST['name'];
    $email$_POST['email'];

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

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


  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Yes, that's right, although I would define the function before calling it.

  5. #5
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you pullo


Bookmarks

Posting Permissions

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