The task is standard, shopping cart on the site. Products are dynamically loaded. I want to make sure that when I click on the "Add to cart" button, two parameters are passed to the servlet (this is the id that I take from the button and the count, the quantity of goods). How to transfer them to the servlet? Which I would like to receive in a servlet through request.getParametr ("id");
var xhr = new XMLHttpRequest(); var send = "{\"id\":" + "\"" + id + "\"," + "\"count\":" + "\"" + count + "\"" + "}"; send = JSON.parse(send); function reqReadyStateChange() { if (xhr.readyState == 4) { var status = xhr.status; if (status == 200) { var data = xhr.responseText; } else { } } } xhr.open("POST", srvUrl, true); xhr.onreadystatechange = reqReadyStateChange; xhr.send(send); } Tried it like this, but servlet returns null