In a spring boot application with rest architecture
I try to do a ajax call
jQuery.ajax({
type: "PATCH",
url: getHostName() + "/members/" + memberId + "/contracts/" + contractId + "?status=CANCEL",
contentType: "application/json",
dataType: 'json',
headers: {
"Authorization": "Basic " + $.cookie('authorization')
},
success: function (data, status, jqXHR) {
$('#modalSaveSuccess').modal('show');
},
error: function (jqXHR, status) {
checkError(jqXHR);
}
});
In the controller,
@PatchMapping(value = "/members/{memberId}/contracts/{contractId}")
public ResponseEntity updateContractStatus(@PathVariable("memberId") Long memberId, @PathVariable("contractId") Long contractId, @RequestParam("status") StatusEnum status) {
if (status == StatusEnum.CANCEL) {
contractService.cancelContract(contractId);
}
return new ResponseEntity(HttpStatus.OK);
}
When i debug i see that return HttpStatus.OK
In javascript that go in the error section with a status of 200 and with a statusText "parsererror"
Response header
HTTP/1.1 200
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Length: 0
Date: Sat, 17 Dec 2016 18:53:13 GMT
You have set
dataType: 'json'
but you are not returning json. Please remove that line and check the result.