Page code where the request is made:
<td class="hidden-480">
<?php $cod_publicacao = $row['cod_publicacao']; ?>
<a data-id="<?php echo $row['cod_publicacao']; ?>" id="updateVisualization">
<?php $arquivo = $row['arquivo'];
echo"<a href='upload/publicacoes/{$razao_social}/{$tipo}/{$titulo}/{$ano}/{$arquivo}'>
<i class='ace-icon fa fa-eye bigger-110 hidden-480'></i> Visualizar Arquivo</a>";
?></a>
</td>
Request Code:
$(document).ready(function(){
$(document).on('click', '#updateVisualization', function(e){
e.preventDefault();
var uid = $(this).data('id'); // it will get id of clicked row
$.ajax({
url: 'updateVisualization.php',
type: 'POST',
data: 'id='+uid,
dataType: 'html'
})
});
});
PHP page:
<?php
include "conexao.php";
$pdo= conectar();
if (isset($_REQUEST['id'])) {
try{
$codigo = intval($_REQUEST['id']);
$SQL = "UPDATE tbl_publicacao SET status = S WHERE cod_publicacao = ?";
$stmt = $pdo->prepare( $SQL );
$stmt->bindValue(1, $cod_publicacao, PDO::PARAM_INT);
$stmt->execute(array(':codigo'=>$codigo));
}catch(PDOException $e){
'ERROR :' . $e->getMessage()."<br>";
'ERROR :' . $e->getCode();
}}
?>
Update:
According to a suggestion, I "put" the codes in a single <a>
tag, however now when clicking, nothing happens, neither opens the pdf nor updates in the database, it follows the new code <td>
:
<td class="hidden-480">
<?php $cod_publicacao = $row['cod_publicacao'];
$arquivo = $row['arquivo'];
echo"<a href='upload/publicacoes/{$razao_social}/{$tipo}/{$titulo}/{$ano}/{$arquivo}' id='updateVisualization' data-id='$cod_publicacao'>
<i class='ace-icon fa fa-eye bigger-110 hidden-480'></i> Visualizar Arquivo</a>";
?>
</td>