AJAX request and PHP class functions

后端 未结 8 882
小鲜肉
小鲜肉 2020-12-08 05:29

How to call a PHP class function from an ajax call

animal.php file

class animal
{     
  function getName()
  {
    return \"lion\";
  }         


        
8条回答
  •  星月不相逢
    2020-12-08 05:51

    Try this: Updated Ajax:

    $("#submit").on('click', (function(e){
    
        var postURL = "../Controller/Controller.php?action=create";
    
        $.ajax({
            type: "POST",
            url: postURL,
            data: $('form#data-form').serialize(),
            success: function(data){
                //
            }
        });
        e.preventDefault();
    });
    

    Update Contoller:

    create();
    }
    
    ?>
    

提交回复
热议问题