I'd like to send a data from my javascript to my struts action. It's just an id, therefore i wonder if there is a better way than to do it through a form.submit();
here is the variable i'd like to send.
var id = $('[data-detailsid="' + $(this).data('headid') + '"]');
What would be the proper way to do it ?
My current js function :
$.ajax({
url: "deleteProduct",
type: 'POST',
data: 'productId=' + id
});
And my struts action :
@Action("/deleteProduct")
@ResultPath("/")
@Result(name = "success", location = "jsp/board.jsp")
public class DeleteAction {
int productId;
@Autowired
private UserDao userDao;
public String execute() {
Product currentProduct = new Product();
currentProduct.setId(productId);
userDao.deleteProduct(currentProduct);
setProducts(userDao.getProducts());
return "success";
}
public void setProductId(int productId) {
this.productId = productId;
}
}