Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Screen {
- constructor() {
- console.log('Created screen');
- }
- process() {
- this.getReports()
- .then(data => {
- this.renderReports(data);
- })
- .catch(err => console.error(`Something went wrong ${err.message}`));
- }
- getReports = async function () {
- try {
- const res = await fetch('http://192.168.0.95:8080/api/reports/', {
- headers: {
- 'Content-Type': 'application/json',
- //Authorization: `Token ${testToken}`,
- },
- });
- if (!res.ok) throw new Error(`Something went wrong.. ${res.status}`);
- return res.json();
- } catch (err) {
- throw err;
- }
- };
- renderReports(reports) {
- console.log(reports);
- }
- }
- const newScreen = new Screen();
- btn.addEventListener('click', function () {
- newScreen.process();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement