I'm sending AJAX request to make simple CRUD happens on my project, asynchronously
I don't need any response from server, I just need to insert, update or delete data on database.
I also learned there must be a response to a request, so I tried some ways to fake it, but all of them didn't feel right.
- return meaningless value
Just return any value like boolean or empty String, and not using it
@PostMapping("/whatever") public @ResponseBody boolean something() { doSomething(); return true; } - return something, but not using it
Almost same as 1, since I'm not using it
@PostMapping("/whatever") public @ResponseBody MyObject something() { doSomething(); return new MyObject(); } - doesn't care about response, just get errors and don't mind it
Use catch or always with ajax request, a lot of errors on console, it really doesn't feel right
@PostMapping("/whatever") public void something() { doSomething(); } @PostMapping("/whatever") public String something() { doSomething(); return "/page/url"; } All of them works as I want, but it makes me thinking there could be a better way to write a code when I don't need any response.
Any advice on this?