blob: 9708e0cc12a6cc588c45320184ad7cebbe146a38 (
plain)
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
39
40
41
42
43
44
|
async function submit() {
const language = document.getElementById("submission-language").value;
const details = document.getElementById("submission-details").value;
const code = document.getElementById("submission-code").value;
const submission = {
problem_id: 2, // TODO validate language and problem id in server
language: language,
details: details,
code: code,
};
const response = await fetch("/submission", {
method: "post",
headers: { "Content-Type": "application/json" },
credentials: "include",
body: JSON.stringify(submission)
});
console.log(response);
const result = await response.json();
console.log(result);
}
async function init() {
const url_params = new URLSearchParams(window.location.search);
const problem_id = url_params.get("problem_id");
const response = await fetch(`/problem/${problem_id}`);
const problem = await response.json();
const problem_div = document.getElementById("submission-problem");
const title = document.createElement("h2");
title.innerHTML = `Problem: ${problem.title}`;
problem_div.appendChild(title);
const description = document.createElement("p");
description.innerHTML = problem.description;
problem_div.appendChild(description);
}
|