What I want to do is send the parameters from Form
to POST
and then through the method GET
consult the BBDD
for room availability and send that result through Ajax
(Vanilla Javascript) to HTML
But from what I was seeing I can not use the methods at the same time. It only works if I only use the method POST
(method="POST") or only the method GET
(method="GET") on the Form.
Here is the query Ajax
:
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "Controlador", true);
xhttp.setRequestHeader('Content-Type', 'text/html');
xhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
document.getElementById("precio").innerHTML = this.responseText;
}
};
xhttp.send();
//document.getElementsByTagName("FORM").submit();
}
And here the method doGet
:
PrintWriter out = response.getWriter();
ReservaDAOImp rv = new ReservaDAOImp();
rsv.setTipoHab(request.getParameter("tipHab"));
rsv.setCodHotel(request.getParameter("hoteles"));
out.print(rv.disponibilidad("select disponibilidad from T_tiphab where tipo=? and codHotel=?", rsv));
When I use the method
GET
inForm
send me to another page with the correct result but when I use it withAjax
the parameters of the form arriveNULL
to Servlet.