I'm working on a GPS/mapping app using Node.js, express, Socket.IO, and MongoDB. The tracker page uses HTML5 geolocation and Socket.IO to send coords to the server and store them into MongoDB. I'm now working on creating user pages so a user can view previously recorded data. I'm currently minus a log in page, so index.html just populates a list of user names and I can select one.
My problem is that I am unsure of how to best pass data such as the username of the selected user to the next page. I have been trying to avoid opening a socket connection to the server just to pass one username but if that is the best way then no problem. I am also aware of localStorage as an option. Here is some code snippets to give you an idea of what I'm working on:
index.html:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function() {
$.ajax({
dataType: "json",
url: "/getusers"
}).done(function(data) {
console.log("--->", data);
for(var i=1; i<data.length; i++) {
$('#list').append("<li><a href=http://localhost:3000/mapPage.html>" + data[i].name + "</a></li>");
}
$("a").click(function(e) {
alert("--->", $(this).html());
//alert("--->", $(e).html());
//alert("--->", $(e).getVal());
//window.localStorage.setItem("username", )
});
});
});
</script>
</head>
<body>
<ul id='list'>
</ul>
</body>
</html>
The ajax is just hitting an express route that asks the MongoDB for collection names (each user has a collection). Also I'm having trouble getting the data from the specific anchor tag I clicked on. So I need to get the user name I clicked on and send it to the "userpage", which, for now would be almost identical to index.html, it would select the specific user collection and show a list of available objects (arrays of map coords);
tl;dr: get data from anchor tag clicked, make data available to next page.