Attempting to make an ajax request in my SpringMVC project has been challenging.
$.ajax({
contentType : 'application/json; charset=utf-8',
type : 'get',
url : 'order/get/'+i,
dataType : 'json',
data : {},
success : function(result) {
alert("Request successful!");
},
error : function(result, status, er) {
alert("Error: "+result+" Status: "+status+" Error:"+er);
}
});
@RequestMapping(value = "/order/get/{id}", method = RequestMethod.GET)
public ResponseEntity<Order> getOrder(
@PathVariable("id") long id) {
Order order = orderService.getOrderById(id);
if (order == null) {
new ResponseEntity<Order>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Order>(order, HttpStatus.OK);
}
Despite the efforts, I am consistently encountering errors. The controller method is returning an object of 'order', but the ajax call keeps throwing 'GET net::ERR_CONNECTION_RESET' error. Why is this happening?