One issue I've encountered in my program is the repetition of code every time I declare an object like a list, save, add, or remove. Each function requires the same lines of code to open a connection to a servlet and then send the request.
//this.ajax.get('./route/action').update('ajax-content');
./route/action // this is path to my Action class-using servlet
I find myself constantly opening connections, specifying the path to the action class (which is a servlet), and then sending the request whenever I need to load a list, delete, or update something.
Is there a way to simplify this process with a function that looks something like this:
this.ajax.get('./route/action');
// 'ajax.content' is the id of the div where I
// want to show the list,where after updating AJAX show the update list to the user.
update('ajax-content');
For example, after adding a user, I'd like to see the changes reflected without reloading the entire page. My project involves Maven, Java EE, Servlet, and JavaScript.