I get 400 Bad Request for the AJAX Post method. I am using Spring Data Recovery Services in Backend. Below is the code that I have on the front end for JS
var url = "/udb/data/SecurityRoleGroup", groupData = {id:"",name:"",accesslevel:"",roles:[]}; groupData.id = groupId.val(); groupData.name = groupName.val(); groupData.accesslevel = groupDescription.val(); groupData.roles = multiselect_to.val(); $.ajax(url, { type: 'POST', dataType: 'json', headers: { 'X-CSRF-Token': _csrfGroup.val(), 'Content-Type' : 'application/json' }, data: JSON.stringify(groupData), contentType: 'application/json', }) .done(function(results) { showMessage.html("Group details are saved successfully."); showMessage.removeClass().addClass("alert alert-success").show(); }) .fail( function(xhr, textStatus, errorThrown){ showMessage.html("Error : Rolegroup AJAX request failed! Please try again."); showMessage.removeClass().addClass("alert alert-danger").show(); });
Although I am serializing JSON data. However, I get a 400 Bad Request error. Could this error occur if any code violates the backend or its problem with the request sent to the server?
JAVA implementation
@RepositoryRestResource(collectionResourceRel = "SecurityRoleGroup", path = "SecurityRoleGroup") public interface SecurityRoleGroupRepository extends PagingAndSortingRepository<SecurityRoleGroup, Long> { }
source share