app.get("/somesite*", async(req, res) = { let results = ""; let jQuery = ""; // res contains an array of JSON objects. Ex. // [ { "text": "My Link", "url": "https://mylink.com" } ] for (let i = 0; i < res.length; i++) { let id = functions.makeId(5); // Creates a random 5 character string. So for example x5jQ2 results += `
`; jQuery += ` $(".${id}").click(function() { console.log("${res[i].url} and also clicked"); $.post("${config.site}/postrequest/", { url: "${res[i].url}", name: "${res[i].text}" }, function(data) { console.log(data); }); });`; } let content = ` ${results} `; res.write(content); res.end(); }); ... app.post("/postrequest*", async (req, res) => { // Handle the post request somehow and write the data. });