where to mount the table in a PHP MVC project with ajax?

Asked

Viewed 166 times

0

Inside the model I have a series of negotiations to show the final result.

//CONTROLLER
public function index(){    
    $this->view->render("views/index.php");
}

public function read(){
    $data = array();
    $data['id'] = $_POST['id'];
    $this->model->showAlgo($data);
}

//MODEL

public function showAlgo($data){
    //Faz um select com o  $data['id'] e retorna uma a table já montada
    $resultadoDaQuery = "<table><tr><td>".$resultado['algumacolunadobanco']."</td></tr></table>";
    echo json_encode($resultadoDaQuery);
}

script:

$.ajax({
    url: "nome/read",
    type: "POST",
    success: function(dados){
        //monta os dados aqui e envia pro html via jquery
    },
    error: function(){}
});
  • what is the correct way to assemble the result?
  • can do this in the model as in the example above and send directly to ajax (in success)?
  • or you must mount the table inside the ajax (in the function success)?

1 answer

0

The HTML code in this case should be in the View.

There is general confusion also about what is model and view, such as using the controller.

Read this recent topic:

/a/116422/4793

Browser other questions tagged

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