Issue
I have an on my index page(thymeleaft page), with a click to call a function in ajax and this ajax method to call a method in the controller, but the method in the controller is not called.
href:
<a href="#" th:onclick="'addproductcart('+${p.id}+')'"><span></span>Add</a>
ajax:
function addproductcart(id){
$.ajax({
type : "GET",
url : "/addproductcart/"+id,
success : function(result){
$('#headsearchproduct').val(result.id);
}
});
};
controller:
@GetMapping("/addproductcart/{id}")
public ResponseEntity<Produtocarrinho> adicionarprodutocarrinho(@PathVariable("id") Long id) {
Produtocarrinho produtocarrinho = new Produtocarrinho();
Produtos produto = produtoRepository.findById(id).get();
produtocarrinho.setId(produto.getId());
produtocarrinho.setFoto1min(produto.getFoto1min());
produtocarrinho.setQuantidade("1");
produtocarrinho.setValor(produto.getPrecoNovo());
ResponseEntity<Produtocarrinho> responseEntity = new ResponseEntity<Produtocarrinho>(produtocarrinho, HttpStatus.OK);
return responseEntity;
}
I had already made a method exactly like that on another page of this project and it worked very well, and I already debugged it and saw that it is not called the controller method, does anyone know where is wrong?
Solution
I solved this, the problem was in the spring security blocking this request
Answered By - Igor Vinicius