You can use JQuery to do an Ajax request to the web server, like:
$.ajax({
url: "ImageRetriever.java",
type: "GET",
data {
imageId: 1234
},
success: function(result) {
$("#imagePath").text(result);
}
});
And then, in the server side, you have a Java servlet / PHP script / C# class that gets the image id, queries the database using that id, and returns the image path. Now, I would post this as well, but without further details (your server side language, how the database looks like, etc) I can't do that, as I'm basically blind