Récupérer un variable GET en ajax
Bonjour,
Je n'arrive pas a récupérer une valeur GET dans mon script php.
Page JS :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| $(function() {
getadresse();
function getadresse() {
$.ajax({
url: '../process.php',
type: 'post',
data: { action: 'adressefetch'
},
success: function (response) {
$('#adresseTable').html(response);
$('#table').DataTable({
order : [0, 'desc'],
});
}
})
}
}) |
process PHP
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| if (isset($_POST['action']) && $_POST['action'] === 'adressefetch') {
$output = '';
if ($db->countadresse() > 0) {
$adresse = $db->adresseread();
$output .= '
<table id="table" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">adresse</th>
<th scope="col">cp</th>
<th scope="col">ville</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
';
foreach ($adresse as $adresses) {
$output .= "
<tr>
<th scope=\"row\">$adresses->id</th>
<td>$adresses->adresse</td>
<td>$adresses->cp</td>
<td>$adresses->ville</td>
<td>
<a href=\"#\" class=\"text-danger me-2 deleteBtn\" title=\"supprimer"></i></a>
</td>
</tr>
";
}
$output .= "</tbody></table>";
echo $output;
} else {
echo "<h3>Aucunes adresses pour le moment</h3>";
}
} |
page requete php
Code:
1 2 3 4 5 6 7 8 9
| public function adresseread()
{
return $this->getconnexion()->query('SELECT * FROM l_adresse WHERE users_id = "'.$_GET['id'].'"')->fetchAll(PDO::FETCH_OBJ);
}
public function countadresse(): int
{
return (int)$this->getconnexion()->query('SELECT COUNT(id) as count FROM l_adresse WHERE users_id = "'.$_GET['id'].'"')->fetch()[0];
} |
Quand je fixe l'ID cela fonction mais pas moyen de lui envoyer l'ID via le get.
avez-vous une solution pour récupérer l'id du client ?
Merci,