Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda