Use php and Ajax class

Asked

Viewed 274 times

0

good morning

The question is as follows, I have a class of "user.class.php", where within it are my attributes, and all methods(Insert, update, delete, search code and etc...)

    private(){
    ...todos os atributos da classe
    }

    public function insert(){
    ....
    }
    public function delete(){
    ....
    }

        function retUsu($id){
            if(is_null($id)){
                return false;
                }else
             $sqlpID = "SELECT * FROM usuario WHERE idu_usujport=".$id;
             $con = $this->con->Connect()->prepare($sqlpID);
             $con->execute();
             $usuario = $con->fetch();
             return json_encode($usuario);   
            }
}

ai I will return to fetch this information with ajax and return in input types "text" from my form. below is the example.

jQuery(document).ready(function($){
    $('#sel_usuario').change(function(){
        var id_user = $(this).val();
        $.ajax({
            url: '../usuario.class.php', //só busco a classe usuário, mas não o método, linha onde fica a duvida. 
            method: 'POST', // Default: GET
            data: { idu_usujport: id_user }, // ID do usuário que você vai pegar do combobox
            success: function(response) {
                // Em caso de sucesso pegar os dados retornados pelo Ajax e popular inputs.
                $('#nome').val(response.nome);
                $('#email').val(response.email);
                $('#senha').val(response.senha);
                $('#imagem').val(response.imagem);
            },
            error: function() {
                // Tratar os erros
            }
        });
    });
});

My question is this, this right the way I am indicating my class in the url:? since all the médodos are together in the same class.

  • In the archive usuario.class.php there is a class instance and code that will properly handle the POST request or there is only the class definition?

  • Anderson, in my user class.class.php I only have the attributes, and the SQL methods, Insert, update, delete, and select nothing else. Now the code that will handle the requests does not exist, that I put in the form example IF(ISSET($_POST['REGISTER'])) so yes it performs an action and inside it I took the instance action ($user->retUsu).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.