1
good morning guys, I’m using js with php, the problem I’m trying is that I’m not getting to understand how to move to the button and the script, follows below to where I left off.
index php.
<button class="fa fa-times btn btn-danger right ml3" id="removerRegistro"></button>
removerRegistro.php
<?php
require "conexao.php";
if(isset($_GET["cli_id"]) && empty($_GET["cli_id"])){
$cli_id = $_GET["cli_id"];
$conex = new conexao();
$conex->deleteDesc($_GET["id"]);
}
Connexion.php
public function deleteDesc($cli_id){
$sql = $this->conexao->prepare("DELETE FROM descricao WHERE cli_id = :cli_id");
$sql->bindValue(':cli_id', $cli_id);
$sql->execute();
}
Ajax removerRegistro.php
<?php
require_once "../database/conexao.php";
if(isset($_GET["id"]) && !empty($_GET["id"])){
$conex = new conexao();
retun json_encode($conex->deleteDesc($_GET["id"]));
}
script js.
$(document).on('click','#removerRegistro', function(event){
event.preventDefault();
var id = $(this).attr('data-id')
})
$.ajax({
url: 'ajax/removerRegistro.php?id=' + id,
type: 'GET',
dataType: 'JSON'
}).done((e) => {
})
Your
script.js
doesn’t make much sense. Is it like that? Because at the click of the button you just assign the variableid
, but does nothing with it; moreover you try to use the value ofid
out of the event to make the requisition and it made no sense.– Woss
In this condition,
isset($_GET["cli_id"]) && empty($_GET["cli_id"])
, I believe the!
in front of theempty
. Moreover, it is not necessary to useisset
andempty
together, because the veryempty
checks if the variable is set. See documentation for details.– Woss