I'm having a bit of trouble trying to create multiple different objects on the page that will all send a get request to the same url but with different parameters in the request. The server should return a page but with different data based on which object was clicked to make the request. It's kind of like a profile picker in a way. Like if I click on person 1's picture it brings me to their profile page but if I click on person 2's picture it brings me to person 2's profile page.
Each person has a unique Id associated with their profile in my database which I have access to on within my client side javascript. I want to include that Id as part of my request to the server when person x's profile picture is clicked.
Below is the client side code I have so far.
//Create row element to be appended to the body
var newRow = document.createElement("div");
newRow.className = "row";
//Iterate through the returned array of JSON objects
for (i = 0; i < response.length; i++)
{
//Create new columns to be appended to the row
var newCol = document.createElement("div");
newCol.className = "col-lg-4 col-sm-6 text-center mb-4";
//Create new image object from data in response
var image = new Image();
image.src = '/uploads/' + response[i].pic;
image.className = "rounded-circle d-block mx-auto patient-img";
var patId = response[i].Id
//Create new anchor object
var link = document.createElement("a");
link.href = 'javascript:loadProfile()'; //When clicked will call function that sends get request to /profile
link.appendChild(image);
newCol.appendChild(link);
//Get patient name from response
var patName = document.createElement("h3");
patName.innerHTML = response[i].name;
newCol.appendChild(patName);
//Append the full column to the row
newRow.appendChild(newCol);
}
I want to include the person's Id as part of my call to loadProfile() but I'm not sure how to. Should I maybe try just appending the persons Id to the href of the anchor object and make a get request like that? I'm using express.js for the web server, jquery to make the client side requests, and mongoDB as my database. Any help or advice would be greatly appreciated!!