If I’m making a social media site for example how do I make the links do what there suppose to do like, edit my profile or upload picture?
So far I just got the AI to make the look of it so far.
If I’m making a social media site for example how do I make the links do what there suppose to do like, edit my profile or upload picture?
So far I just got the AI to make the look of it so far.
Whether you just need to create visual links on the page or build the entire SNS site system from scratch makes a world of difference in difficulty…![]()
A link “works” only when two things exist.
For a social site, “Edit profile” and “Upload picture” are not just styling. They are routes, forms, API endpoints, and storage.
<a href="..."> when the click should go to a URL. The href is what makes it an actual link. (MDN Web Document)<button> when the click should do an action like save, upload, open a dialog. (MDN Web Document)Beginner rule:
Basic HTML:
<a href="/settings/profile">Edit profile</a>
Now you must make /settings/profile exist.
Two common setups:
<form id="profileForm">
<input name="displayName" placeholder="Display name" />
<textarea name="bio" placeholder="Bio"></textarea>
<button type="submit">Save</button>
</form>
Use fetch and check response.ok. fetch() does not automatically “throw” on HTTP errors like 404. (MDN Web Document)
<script>
document.getElementById("profileForm").addEventListener("submit", async (e) => {
e.preventDefault();
const data = Object.fromEntries(new FormData(e.target));
const res = await fetch("/api/me", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!res.ok) return alert("Save failed");
alert("Saved");
});
</script>
Your server needs something like:
PATCH /api/me → validate input → update database row for the current userSecurity pitfall to avoid:
/api/users/123. That is an IDOR risk. (OWASP Cheat Sheet Series)Uploads are not normal links. They are file inputs plus a request.
<input type="file"> is the standard control. ([MDN Web Document][6])
<input id="avatar" type="file" accept="image/*" />
<button id="uploadBtn" type="button">Upload</button>
FormData builds the request body in the same format as a form using multipart/form-data. (MDN Web Document)
<script>
document.getElementById("uploadBtn").addEventListener("click", async () => {
const file = document.getElementById("avatar").files[0];
if (!file) return alert("Choose a file first");
const fd = new FormData();
fd.append("avatar", file); // field name "avatar" must match the backend
const res = await fetch("/api/me/avatar", { method: "POST", body: fd });
if (!res.ok) return alert("Upload failed");
alert("Uploaded");
});
</script>
Note:
multipart/form-data for file uploads. (MDN Web Document)FormData with fetch, the browser sets the correct multipart headers for you. (Common beginner mistake is forcing Content-Type manually.)Example if you use Node + Express: use Multer. It is made for multipart/form-data and will not process non-multipart requests. (Express)
// deps: npm i express multer
import express from "express";
import multer from "multer";
const app = express();
const upload = multer({ dest: "uploads/" });
app.post("/api/me/avatar", upload.single("avatar"), (req, res) => {
// req.file is the uploaded file
// Save path or URL into the logged-in user's profile in your DB
res.json({ ok: true });
});
app.listen(3000);
For a beginner project, saving to uploads/ is fine.
For a real app, you usually store images in object storage and store the URL in the database.
Security basics for uploads:
Does your “link” have a real href? (MDN Web Document)
Are you using a <button> for actions? (MDN Web Document)
DevTools → Network:
fetch does not throw on 404 by default. (MDN Web Document)If routing works only when clicking but breaks on refresh, it is likely the SPA rewrite problem. (Stack Overflow)
For uploads, confirm the backend is parsing multipart. (Express)
href. (MDN Web Document)<input type="file">. ([MDN Web Document][6])response.ok. (MDN Web Document)href and real routes matter. (MDN Web Document)response.ok. (MDN Web Document)