2
Hello, I am making a request in Ajax, and there is an error where the value of the code of the line clicked (in a table) is not passed to Ajax, but I have another example that works perfectly and this is in error. I believe that the possible error is because when the user clicks on the link, in theory the system should update in the table and then send to PDF view, but must be giving conflict internally
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>
Requisition 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 suggestion I "joined" the codes in a single tag <a>
however now when clicking, nothing happens, neither opens the pdf nor updates in the bank, follows the new code of <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>
You’re putting a tag
a
inside one and that is not allowed. http://stackoverflow.com/questions/13052598/creating-anchor-inside-anchor-tag– Jeferson Almeida
I was doubtful about it but already understood, thank you very much, you have some suggestion of how to do the update in the bank and open the PDF on the system?
– UzumakiArtanis
First thing you have to do is join these 2 elements
<a>
in a single, moreover, qnd you click it comes to hit in PHP, gives some error message?– Jeferson Almeida
Nothing, stamping(I think that’s it) he doesn’t even get the values, he passes beaten, but thanks for the help, I’ll try to do and show the results
– UzumakiArtanis
Join the tag elements
<a>
, may be that he is not even gone to PHP because of this, if you are that I try to help you– Jeferson Almeida
@Jefersonalmeida updated the data
– UzumakiArtanis
Worked now?
– Jeferson Almeida
No, now by clicking, nothing happens, neither opens the pdf nor updates in the bank
– UzumakiArtanis
@Jefersonalmeida updated the Post
– UzumakiArtanis
Replaces your
data: 'id='+uid
fordata: {id: uid}
, the ideal was also vc debug the return of your post in php to know if there is an error or if the id arrives correctly in it– Jeferson Almeida
@Jefersonalmeida now it just updates and does not open the pdf, but it is already a progress if you continue to help I will be grateful
– UzumakiArtanis
If I already opened on the other page there was no problem, but I can’t open even with target="_Blank" and if I click open link on new tab it already opens normal
– UzumakiArtanis
I will formulate an answer with everything here
– Jeferson Almeida