I've been utilizing AJAX in conjunction with the Play 2 framework to send requests and execute actions on the server side.
Learn how to make an AJAX request with a common button in Play 2.x
Troubleshooting Jquery and Play Framework 2 JavaScript router issues
However, I'm now interested in sending a request to the server, querying a database, and receiving a response back via AJAX to update an image or change text dynamically.
What would be the recommended approach for achieving this?
At the moment, my setup includes:
A controller function:
public static Result delete(Long id) {
//...
return ok();
}
The corresponding view:
<script type="text/javascript">
$("#delete").click(function() {
var id = $(this).attr("data-id");
alert(id);
jsRoutes.controllers.Items.delete(id).ajax({});
return false;
});
</script>