Criando datatable com array e ajax
Boa tarde.
Estou criando uma datatable, com array e ajax, e quero poder quando clicar em link na tabela, chama uma requisição ajax, porem não estou conseguindo fazer a mesma.
Código PHP:
<?php
include('functions.php');
$res = $pdo->prepare("SELECT * FROM vagas");
$res->execute();
// Aqui está o link para clicar e fazer uma requisição, o link é TESTAR
$data = array();
while($resu = $res->fetch(PDO::FETCH_ASSOC)) {
$data[] = array('Testar'=>'<a href="#" id="teste">Testar</a>','Cidade'=>$resu['cidade'], 'Bairro'=>$resu['bairro'], 'Rua'=>$resu['rua'], 'Numero'=>$resu['numero'], 'Email'=>$resu['email'], 'Titulo'=>$resu['titulo'], 'Obs'=>$resu['obs']);
}
$results = array(
"sEcho" => 1,
"iTotalRecords" => count($data),
"iTotalDisplayRecords" => count($data),
"aaData"=>$data);
while($row = $res->fetch(PDO::FETCH_ASSOC)){
$results["data"][] = $row ;
}
echo json_encode($results);
?> Código HTML:
<link rel="stylesheet" type="text/css" href="datatable-ajax/css/jquery.dataTables.css">
<script type="text/javascript" language="javascript" src="datatable-ajax/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="datatable-ajax/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" >
$( document ).ready(function() {$('#vagas').dataTable({
"oLanguage": {
"sLengthMenu": "Mostrar _MENU_ registros",
"sZeroRecords": "Nenhuma vaga encontrada em nosso banco de dados.",
"sInfo": "Mostrando de _START_ ate _END_ de _TOTAL_ registros",
"sInfoEmpty": "Nenhuma vaga para ser exibido",
"sInfoFiltered": "(Filtrado de _MAX_ registros no total)",
"sSearch":"Pesquisar:",
"oPaginate": {
"sFirst": "Primeira",
"sLast": "Última",
"sNext": "Proxima",
"sPrevious": "Anterior"
}
},
"bProcessing": true,
"sAjaxSource": "datatable-ajax/vagas.php",
"aoColumns": [
{ mData: 'Testar' } ,
{ mData: 'Cidade' } ,
{ mData: 'Bairro' } ,
{ mData: 'Rua' },
{ mData: 'Numero' },
{ mData: 'Email' },
{ mData: 'Titulo' },
{ mData: 'Obs' }
]
});
});
</script>
//estou testando esse pequeno script, pegando o ID da tabela e exibir um alert, porem sem sucesso
<script>
$(function(){
$('#teste').click(function(){
alert('ok');
});
});
</script>
</head>
<body>
<table id="vagas" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th align="left" width="120">Testar</th>
<th align="left" width="120">Cidade</th>
<th align="left" width="120">Bairro</th>
<th align="left" width="150">Rua</th>
<th align="left" width="100">Numero</th>
<th align="left" width="150">Email</th>
<th align="left">Titulo</th>
<th align="left" width="250">OBS</th>
</tr>
</thead>
</table>
</body>
</html> Se precisar, explico melhor.Discussão (4)
Carregando comentários...