I know this may be asked before, but I have tried everything in stackoverflow and nothing has worked. I am using Spring Security so idk if this has anything to do. Having said that, the ajax POST request simply does not reach my controller, not even a error message or anything. The ajax POST request returns "sucess" but nothing happens.
I have tried (Send json with Ajax to Spring MVC) (How to pass Json object from ajax to spring mvc controller?) (Spring controller not getting JSON POST data from JS file) and a few more.
JS
function cartData(){
//var prods = [];
//prods = JSON.parse(localStorage.getItem("cart"));
var thing = {id: "1",cant:"1"};
//console.log(prods);
$.ajax({
type:"POST",
contentType: "application/json; charset=utf-8",
url: 'cart',
data: thing,
success : function(result) {
alert('success');
},
error : function() {
alert("not working");
}
});
}
Controller
//Class
public class Thing
{
private String id;
private String cant;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCant() {
return cant;
}
public void setCant(String cant) {
this.cant = cant;
}
}
//Controller
@RequestMapping(value="/cart",method=RequestMethod.POST)
public @ResponseBody String cart(@RequestBody Thing thing, HttpServletRequest request) {
System.out.println("Got Inside");
return "public/carrito";
}