diff --git a/app/views/assignments/index.php b/app/views/assignments/index.php index cc9eb0ee7762b60552a6912df8b66406f50954ce..34219a4af16c62461993fd0831433563e649e910 100644 --- a/app/views/assignments/index.php +++ b/app/views/assignments/index.php @@ -9,6 +9,8 @@ </div> <script> - const sid = <?php echo $_GET['sid'];?> + const sid = <?php echo json_encode($_GET['sid']); ?>; + const uid = <?php echo json_encode($data['user_id']); ?>; </script> + <script src="/public/js/assignments.js"></script> \ No newline at end of file diff --git a/app/views/assignments/submit.php b/app/views/assignments/submit.php index decc23ce27ecd3e1c68acba9aaa96b1049d0c011..24de200ab55d80660fb9ecd116c0258208fb146f 100644 --- a/app/views/assignments/submit.php +++ b/app/views/assignments/submit.php @@ -18,5 +18,6 @@ <script> var sid = <?php echo $_GET['sid'];?>; var aid = <?php echo $_GET['aid'];?>; + const uid = <?php echo json_encode($data['user_id']); ?>; </script> <script src="/public/js/submit.js"></script> \ No newline at end of file diff --git a/public/js/assignments.js b/public/js/assignments.js index 66e80af1fd731371781133773913d38dd04a5aae..4a7c1d139f9cd5084d42f4df0fb5650da0f70075 100644 --- a/public/js/assignments.js +++ b/public/js/assignments.js @@ -7,7 +7,9 @@ function renderAssignments(){ const xhr = new XMLHttpRequest(); xhr.open("GET", `http://localhost:5001/api/assignment/${sid}`) - + xhr.setRequestHeader("user_id", uid); + console.log(uid) + console.log("ASSIGNMENT JS") xhr.onload = () => { const res = JSON.parse(xhr.response); diff --git a/public/js/submit.js b/public/js/submit.js index ab0b85cb9d6e03bca051c9aeaad4ebad243e5d95..d0071ea0f1ca65b944fcd99274af30a69caa9b78 100644 --- a/public/js/submit.js +++ b/public/js/submit.js @@ -1,15 +1,15 @@ const render = () => { const xhr = new XMLHttpRequest(); xhr.open("GET", `http://localhost:5001/api/assignment/${sid}/${aid}`) - + xhr.setRequestHeader("user_id", uid); xhr.onload = () => { const res = JSON.parse(xhr.response); console.log(res.data); - + console.log(res.data.assignments[0]) if (res.status === 'success') { - title.innerHTML = res.data.assignment_name - description.innerHTML = res.data.assignment_description + title.innerHTML = res.data.assignments[0].assignment_name + description.innerHTML = res.data.assignments[0].assignment_description } } @@ -18,29 +18,32 @@ const render = () => { } const title = document.getElementById("assignment_name"); const description = document.getElementById("description"); - const submitForm = () => { const xhr = new XMLHttpRequest(); - xhr.open("POST", `http://localhost:5001/api/files/scholarship/${sid}/assignment/${aid}`) + const formData = new FormData(); + + // Get the file input element + const fileInput = document.getElementById('file'); + + // Append data to the FormData object + formData.append("uid", uid); + formData.append("file", fileInput.files[0]); // Assuming fileInput is your file input element + + xhr.open("POST", `http://localhost:5001/api/files/scholarship/${sid}/assignment/${aid}`); xhr.onload = () => { const res = JSON.parse(xhr.response); - console.log(res.data); if (res.status === 'success') { - - title.innerHTML = res.data.assignment_name - description.innerHTML = res.data.assignment_description - + // Update the HTML elements with the response data + document.getElementById('assignment_name').innerHTML = res.data.assignment_name; + document.getElementById('description').innerHTML = res.data.assignment_description; } } - const body = { - "uid": uid, - "file_path": file_path - } - - xhr.send(body) + xhr.send(formData); } + + document.addEventListener("DOMContentLoaded", render); \ No newline at end of file