invoke doPost in java servlet through ajax
Hey.=)
I'm trying to invoke my doPost method in java servlet through ajax command.
Don't seem to get it right.
I got this code in the doPost method in my servlet:
- String title = request.getParameter("title");
- String price = request.getParameter("price");
- String quantity = request.getParameter("quantity");
- // and alot more code
Got this code in my HTML:
- <span>Title:</span> <input type="text" name="title" /><br />
- <span>Price</span><input type="number" step="0.01" name="price" /><br />
- <span>quantity</span><input type="number" name="quantity" /><br />
- <input type="button" value="add Item" id="addItemToShoppingCart" />
and this code in my js file:
- $(function() {
- $("#addItemToShoppingCart").click( function() {
- $.post("ShoppingCart")
- })
- })
Of course it don't work.
I want to make the call to doPost and send the params without form and submit.