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)?