diff --git a/index.html b/index.html index 2cd1f65..81abfad 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,7 @@ + diff --git a/m5.js b/m5.js index 7ab42e3..f942a67 100644 --- a/m5.js +++ b/m5.js @@ -1,21 +1,34 @@ const url = "http://localhost:4377/"; // const reQ = new Promise(rej); -const fetchData = async (url) => { +const fetchData = async () => { const req = new XMLHttpRequest(); + req.open("GET", url); // open channel + try { - req.open("GET", url); // open channel req.send(); // send request - const resp = await req.response; - console.log(req); - return resp; + req.responseType = 'json' + req.onreadystatechange = ()=>{ + + if(req.readyState== 4){ + let data = req.response + + Object.values(data.lessons).map( + (e)=>{ + getData.appendChild( + Object.assign(document.createElement("p"),{ + innerText: e.id + " " + e.topic + " " + e.description + })) + }) + + return data + } + + } + } catch (error) { console.log(error); return error; } }; -fetchData(url) - .then((data) => { - console.log(data); - }) - .catch((error) => console.log(error)); +fetchData() \ No newline at end of file diff --git a/server/data.js b/server/data.js new file mode 100644 index 0000000..07cef4d --- /dev/null +++ b/server/data.js @@ -0,0 +1,23 @@ +export const lessons =[{ + + topic:'Module 1', + id:1, + description:'', + outcomes:['','',''] + +}, { + topic:'Module 1', + id:1, + description:'', + outcomes:['','',''] + }, { + topic:'Module 1', + id:1, + description:'', + outcomes:['','',''] + }, { + topic:'Module 1', + id:1, + description:'', + outcomes:['','',''] + },] \ No newline at end of file diff --git a/server/index.js b/server/index.js index 718e872..e1bdacd 100644 --- a/server/index.js +++ b/server/index.js @@ -1,11 +1,12 @@ import express from "express"; +import { lessons } from "./data"; import cors from "cors"; const app = express(); const port = 4377; app.use(express.json()); app.use(cors({ origin: "*" })); app.get("/", (req, resp) => { - resp.status(200).send({ message: "Voilor!", lessons: [4, 5, 5] }); + resp.status(200).send({ message: "Voilor!", lessons}); }); app.listen(port, () => { console.log("Server running on port http://localhost:4377");