quand je lance avec php -S localhost:8000 voici ce que j'ai : Blocage d’une requête…
- User
quand je lance avec php -S localhost:8000 voici ce que j'ai : Blocage d’une requête multiorigine (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur http://localhost:3000/mangas. Raison : échec de la requête CORS. Code d’état : (null).
TypeError: NetworkError when attempting to fetch resource. userprovider.js:13:15 Uncaught (in promise) TypeError: mangas is undefined render http://localhost:8000/view/allmangas.js:7 allmangas.js:7:5 render http://localhost:8000/view/allmangas.js:19 AsyncFunctionNext self-hosted:852
import UserProvider from "../services/userprovider.js";
export default class AllMangas { async render(tag) { const mangas = await UserProvider.fetchMangas(); const ul = document.createElement(tag); mangas.forEach((manga) => { const li = document.createElement("li"); li.textContent = manga.title + " | Alternative titles : " + manga.alternativeTitles; li.dataset.mangaId = manga.id; li.addEventListener("click", async () => { const mangaId = li.dataset.mangaId; this.renderDetails(mangas, mangaId, "div"); }); ul.appendChild(li); }); document.body.appendChild(ul); }
async renderDetails(mangas, mangaId, tag) { let ul = document.querySelector("#mangaId"); const div = document.createElement(tag); div.textContent =
Genre: ${manga.genres}; li.textContent =Type: ${manga.genres}; ul.appendChild(div); } } import UserAll from "./view/allmangas.js";let userAll = new UserAll(); window.addEventListener("load", () => { userAll.render("ul"); });export const ENDPOINT = "http://localhost:3000/mangas";import {ENDPOINT} from '../config.js';
export default class UserProvider {
static fetchMangas = async () => { try { const response = await fetch(ENDPOINT);
const data = await response.json(); console.log(data); return data; } catch (error) { console.error(error); }}
}
// récupèrez les détails d'un user en cherchant par id // faire le delete, l'ajout et la modification d'un user -> utiliser l'outil jsonserver
- Assistant