I send a request to the server - I save the data from the form to the database (all the rules are here), and I try to return the updated data from the database to the server but the ajax section has an error section, and the debugger indicates a successful request

00:29:44.587 [http-bio-8080-exec-6] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 00:29:44.587 [http-bio-8080-exec-6] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request 

ajax code

  $.ajax({ type: 'post', contentType: 'application/json; charset=utf-8', url: 'addAcc', dataType: 'json', data: JSON.stringify(acc), success: function (result) { alert('its ok'); //alert(result); }, error : function (xhrv) { //alert("error"); alert(JSON.stringify(xhrv)); } }); 

PS: JSON.stringify (xhrv) returns 0 status, 0 stage and error text

controller:

 @RequestMapping (value = "addAcc", method = RequestMethod.POST) @ResponseBody public ResponseEntity<String> getBooking(@RequestBody AccountDto accDto, BindingResult bindingResult) { System.out.println("\n\n\n\n\n data is on server \n\n\n\n"); if (!(accountService.findByName(accDto.getName()) == null)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Account already exsists"); } //todo: if (accountValidator.validateAccount(accDto)); Account acc = new Account(accDto); accountRepo.save(acc); System.out.println("\n\n\n\n\n data is on sevbxcvbnrver1 woo \n\n\n\n"); List<AccountDto> listAccDto = accountService.getAccDto(accountRepo.findAll()); System.out.println("\n\n\n\n\n data is on sevbxcvbnrver2 woo \n\n\n\n"); return ResponseEntity.status(HttpStatus.OK).body(new Gson().toJson(listAccDto)); } 

PS: sout-you all displayed

I would be very grateful for the help

  • Open the browser console and see with what code the HTTP response came. Open the console or application log and see which exception it threw out. Perhaps a serialization error or something else. - enzo

1 answer 1

The problem was that the button (by which the request was being executed) was of type submit - because of what the request-a was interrupted, and the client received an empty response