It does not return the value of AJAX

0

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

    
asked by bsg 11.10.2018 в 19:26
source

1 answer

0

I think it's URL, on the page index.jsp is different from the product.jsp and in the POST request is made to that servlet but it would be jsp / actionServlet.

You can easily leave doubts with the browser debug and verify which URL is making the request

    
answered by 11.10.2018 в 21:17