I want to send value with ajax to spring java. in this case, I want send value with POST method but failed. before I use ajax, I use Swagger (plugin) for test post method run or not. when I use swagger, no problem for send value but I have problem in ajax.
in ajax:
var url = "http://localhost:8085/SpringNew/tesinsert";
var data, view = this;
data = {
"kodekasus" : 19,
"nama" : "newnama",
"isdelete" : null,
"createdby" : "barunih",
"createddate" : null,
"updatedby" : "barunih",
"updateddate" : null
}
$.ajax({
type : "POST",
data : data,
url : url,
processData : false,
contentType : 'application/*',
success : function(data) {
console.log("success!");
},
error : function(e) {
}
});
spring controller:
@PostMapping(value={"/tesinsert"}, consumes=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<?> insert(@RequestBody KasusEntity user) throws Exception {
Map result = new HashMap();
userService.insertTabel(user);
return new ResponseEntity<>(result, HttpStatus.CREATED);
}
the error show:
jquery-dbg.js:9203 OPTIONS http://localhost:8085/SpringNew/tesinsert 403 (Forbidden) XMLHttpRequest cannot load http://localhost:8085/SpringNew/tesinsert. Response for preflight has invalid HTTP status code 403
how to fix this problem? thanks.