0
I am developing a code and the section related to displaying the data that is in SQL for HTML Table are not working. In this case I created a function in my DAO with the SQL query and passed to a kind of Controller. In HTML, I made a Jquery request calling this controller, but it is not working. Could someone explain to me what is wrong or has some other kind of solution
Below is the code (first the excerpt from my DAO file)
//Função para listar os registros
public function listarOperadoras() {
//Cria o bloco Try Catch para exibir os resultados
try {
$querySelect = "
SELECT [operadora],[sigla],[observacao] FROM [dbo].[tbl_oper_escalona]
";
abreConexao(); //Abre a conexão com o banco de dados
global $sql; //Variavel para efetuar a Conexão
$result = $sql->prepare($querySelect); //Prepara a Consulta
$result->execute(); //Executa a Consulta
sleep(1); //1 Segundo
$json_result = json_encode($result->fetchAll(PDO::FETCH_ASSOC));
fechaConexao();
} catch (Exception $e) {
print "Ocorreu um erro: <code style='color: red;>".$e->getMessage."</code>";
}
return $json_result;
}
Now my 'Controller' in case I’m using a Switch Case, the Register option is already done and working so I’m only posting the 'View' that is showing the defect.
case 'Visualizar':
$listOperadoras = new DaoOperadoras();
$listOperadoras->listarOperadoras();
break;
And now the HTML code
<!DOCTYPE html>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!--CSS Bootstrap e Próprios-->
<link rel="stylesheet" type="text/css" href="../LIB/CSS/bootstrap.min.css"/> <!--BootStrap-->
<link rel="stylesheet" type="text/css" href="../LIB/CSS/newPages.css"/><!--CSS Adicional-->
<!--Bootstrap JS-->
<script type="text/javascript" src="../LIB/JS/jquery3.1.1.js"></script>
<script type="text/javascript" charset="utf-8" src="../LIB/JS/jquery-1.11.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../LIB/JS/bootstrap.min.js"></script>
<!--Auto Complete Source-->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style type="text/css">
body {
background-color: #F0F8FF;
}
</style>
<script type="text/javascript">
$(document).ready( function() {
//Captura o retorno da tabela que contem as unidades
$.getJSON('../CONTROLLERS/OperadorasController.php?opcao=Visualizar', function(data) {
var Operadoras = ""; //Variavel Operadora que será montada
for (var i = 0; i < data.length ; i++) {
operadoras += "<tr>";
operadoras += "<td>" + data[i].operadora + "</td>";
operadoras += "<td>" + data[i].sigla + "</td>";
operadoras += "<td>" + data[i].observacao + "</td>";
operadoras += "<td>";
operadoras += "<button type='button' title='Editar' class='btn btn-link' id='btnEdit'>";
operadoras += "<i class='fa fa-cut' style='font-size:20px; color:#0066F8;'></i>";
operadoras += "</button>";
operadoras += "</td>";
operadoras += "<td>";
operadoras += "<button type='button' title='Excluir' class='btn btn-link' id='btnExclui'>";
operadoras += "<i class='fa fa-eraser' style='font-size:20px; color:#0066F8;'></i>";
operadoras += "</button>";
operadoras += "</td>";
operadoras += "</tr>";
}
//Preenche a tabela
$("#exiOperadoras").html(operadoras);
});
});
</script>
<table class="table table-striped table-bordered table-responsive">
<thead class="bg-primary">
<tr>
<th>Nome da Operadora</th>
<th>Sigla</th>
<th>Obs</th>
<th>Alterar</th>
<th>Excluir</th>
</tr>
</thead>
<tbody id="exiOperadoras">
</tbody>
</table>
Thank you in advance
What exactly is your doubt?
– Leandro Angelo
In case I need the data of my query to appear in the HTML table, for this I am using the Script in Jquery the beginning of HTML.
– Fernando Henrique Gonçalves
Look at my observations.
– Leandro Angelo