Skip to content
Snippets Groups Projects
Commit 13e0c2e8 authored by MARCO Jonathan's avatar MARCO Jonathan
Browse files

:sparkles: Add AJAX

parent 5ae0dcfd
Branches
No related merge requests found
ajax.php 0 → 100644
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script type="module" src="assets/js/ajax.js" defer></script>
</head>
<body>
<button>Envoyer requête</button>
</body>
</html>
\ No newline at end of file
document.querySelector('button')
.addEventListener('click', async () => {
console.log('avant la requete')
// fetch('http://localhost:8000/assets/php/requestAjax.php')
// .then((response) => {
// console.log('requete terminée')
// })
// .catch((error) => {
//
// })
// .finally(() => {
//
// })
try {
const response = await fetch(
'http://localhost:8000/assets/php/requestAjax.php')
const data = await response.json()
console.log(data)
} catch (error) {
console.log(error)
}
console.log('après la requete')
})
\ No newline at end of file
<?php
require_once 'db.php';
$users = $pdo->query('SELECT * FROM user')
->fetchAll();
echo json_encode(
["users" => $users]
);
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment