Get id via URL in JS sent by PHP

Asked

Viewed 77 times

0

I have a code that plays an ID in HTML for a link:

<a href="javascript:confirmacao(<?php echo $row['idfoto'] ?>)"> <i class="fas fa-trash"></i></a>

Already in Javascript I have the code that calls the file delete.php, that takes the ID.

function confirmacao(id) {
var resposta = confirm("Tem certeza que deseja remover essa informação?");

if (resposta == true) {
    $.ajax({
        url: '/delete.php?delete_id=' + id,
        type: 'GET',
        dataType: 'json'
    }).done(function (data) {
        $.get("/read.php", {}, function (data, status) {
            $('.read_content').html(data);
        });
    });
}
}

I made a modification and created a function inside the ready jQuery as above, which is giving this error when I click on the link.

VM499:1 Uncaught Referenceerror: confirmation is not defined at :1:1 (Anonymous) @VM499:1

Are you saying that the function is not set, will have something to see with jQuery?

  • 1

    The function needs to be declared in the global scope to be called the way you did. And in your code must be in the scope of a jq load/ready Handler.

  • She’s inside $(document).ready(function () { }

  • So, exactly what I thought, you need to take it from there and leave it in the global scope.

  • There is some way to change this function and to keep it within the scope of the ready so of Jquery?

  • If she’s in the global scope she’ll also be in the ready scope. just move her out.

  • There’s only one problem, I don’t know if on account of it’s out of scope, the $.get is not working to display the data in the div and updating the information.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.