Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express api #195

Merged
merged 7 commits into from
Oct 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added function to handle onclick event of hyperlink
TilteD24 committed Oct 13, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
hiyuki2578 Shota Tsunehiro
commit 42cb8a81bc34f16039c1303c1183739fdbf6be32
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -73,4 +73,42 @@ function sendMail() {
+ encodeURIComponent(" <" + document.getElementById('contactEmail').value + ">")
+ "&body=" + encodeURIComponent(document.getElementById('contactText').value);
window.location.href = link;
}

async function postFormDataAsJson({ url, formData }) {
const plainFormData = Object.fromEntries(formData.entries());
const formDataJsonString = JSON.stringify(plainFormData);
//console.log(formDataJsonString);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: formDataJsonString,
mode: "cors",
});

if (!response.ok) {
const errorMessage = await response.text();
throw new Error(errorMessage);
}

return response.json();
}

async function handleFormSubmit() {
const username = prompt("Enter your Discord username");
//console.log(username);
const form = document.getElementById("discord-form");
//console.log(form);
try {
const formData = new FormData(form);
formData.append("Discord", username);
//console.log(formData);
const url = "http://localhost:3000/cweb/contactus";
const responseData = await postFormDataAsJson({ url, formData });
} catch (err) {
console.log(err);
}
}