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

0

Within the model I have a series of discussions 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 I do this in the model as in the example above and send directly to ajax (in success )?
  • or should you mount the table inside ajax (in the success function)?
asked by anonymous 04.03.2016 / 01:24

1 answer

0

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

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

Read this recent topic:

link

    
04.03.2016 / 10:43