I have an index in the path webcontent / index.jsp and it calls a servlet through ajax and returns the value
$(document).ready(function(){
$.post('actionServlet', {
valor: "1"
},function(responseText) {
alert(responseText)
$('#resultado').html(responseText);
});
})
then I have another jsp in webcontent / jsp / productos.jsp and it has that same script but inside a function click
$('#enviar').click(function() {
var producto = $('#Fproducto').val();
var unidades = $('#Funidades').val();
alert("Hola");
$.post('actionServlet', {
valor: "1"
},function(responseText) {
alert(responseText)
$('#resultado').html(responseText);
});
});
because at the moment when pressing the button it does not return anything to me. Only the alert ("Hello") and not the ok that the other one returns.
This is the servlet, I use the same for the two JSP
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType( "text/html; charset=iso-8859-1" );
PrintWriter out = response.getWriter();
String valorServlet = request.getParameter("valorServlet");
out.println("OK");
}
I have tried everything but I can not find the problem. Any solution? Thank you very much