Calling PHP function in a class

2

Good afternoon, I'm creating a simple system in PHPOO with MVC and would like to execute a function inside the controller with a jquery call. I do not want to call the controller in html, I want a js to do this work for me. I tried to do this: My controller is in controller / UsersController. Class:

<?php
class UserController{
   public function teste(){
       echo "ok";
   }
}
?>

and JS:

$("#btn-login").click(function(){
        var data = $("#login-form").serialize();

        $.ajax({
            type : 'POST',
            url  : 'UserController.php', 
            data : data,
            dataType: 'json',
            beforeSend: function()
            {   
                $("#btn-login").html('Validando ...');
            },
            success :  function(response){                      
                if(response.codigo == "1"){ 
                    $("#btn-login").html('Entrar');
                    $("#login-alert").css('display', 'none')
                    window.location.href = "home.php";
                }
                else{           
                    $("#btn-login").html('Entrar');
                    $("#login-alert").css('display', 'block')
                    $("#mensagem").html('<strong>Erro! </strong>' + response.mensagem);
                }
            }
        });
    });

});

I want to run the test function inside the Class.

Thanks for the help.

    
asked by anonymous 24.10.2017 / 19:37

0 answers