Skip to content

Commit

Permalink
Remove front-end wrong parameter/lack of parameter handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yinxoxo committed Jul 8, 2024
1 parent f85e1d6 commit a5a89df
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions Week3/NodeJS/public/sum.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,14 @@ <h1 id="result"></h1>
numberForm.addEventListener("submit", (event) => {
const numberValue = document.querySelector("input").value;
event.preventDefault();
if (numberValue === "") {
result.textContent = "Lack of Parameter";
} else if (
!Number.isInteger(Number(numberValue)) ||
numberValue <= 0 ||
isNaN(numberValue)
) {
result.textContent = "Wrong Parameter";
} else {
fetch(`/getData?number=${numberValue}`)
.then(function (response) {
return response.text();
})
.then(function (data) {
result.textContent = `${data}`;
});
}

fetch(`/getData?number=${numberValue}`)
.then(function (response) {
return response.text();
})
.then(function (data) {
result.textContent = `${data}`;
});
});
</script>
</html>

0 comments on commit a5a89df

Please sign in to comment.