Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Ajax - $.ajax call, with PATH method, is generated without body

I need to call this patch method from Javascript. But the request's body is not seted. Always is void. Is like something more need to be seted at the $.ajax parameters to send the request body. I know the issue is at the body, because if I set at server side the bady as mandatory, the call works, also works if I change just the call type to "POST". But I need a Patch with body.

At server side is working fine (JAVA and Spring):

@PatchMapping
@ResponseStatus(code = HttpStatus.OK)
@Operation(description = "Update User record")
ResponseEntity<UserDTO> updateUser(
    @PathVariable("userId") @Parameter(description = "User", required = true, in = ParameterIn.PATH) Long userId,
    @NonNull @RequestBody UserDTO userDTO);
}

At JS side (The error for sure is here):

var url = ...
var dataStatus = {"status": "A"};
$.ajax({
    url : url,
    type : 'PATCH', 
    contentType : 'application/json',
    processData: false,
    dataType: 'json'
    async : false,
    cache:          false,
    crossDomain:    true,     
    data : JSON.stringify(dataToSend),
    success : function(data) {
        if (data == null) {
            console.error("Error");
        }
        
        if (callback) {
            callback(data);
        }
    },
    error : function(error) {
        console.error("Ajax call error occurs during...");
    },
    beforeSend : function(xhr) {
        debugger;
        xhr.setRequestHeader('Authorization', 'Bearer ' + sessionStorage.accessToken);
        xhr.setRequestHeader('Cache-Control', 'no-cache');
        xhr.setRequestHeader('X-Xss-Protection', '1; mode=block');     
    }
});

The call works but the request's body allways is null. But if I change the call type to "PUT" or "POST" the request's body is setted correctly, but I need a "Patch" call. Must I add any other http header or change something?

Thanks!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!