Ajax Request Returning in White

0

Alright?

My question is this: I am making an ajax request for my servlet and its return is being blank.

JS:

$('#pesquisar').click(function() {
    $.ajax({
        url: '../UsuarioController',
        type: 'POST',
        data: {nome_pesquisa: $('#nome_pesquisa').val()},
        success : function(data) {
            console.log(data);
        },
        error: function(){
            console.log("erro");
        }
    });
    return false;
});

Servlet:

if(request.getParameter("nome_pesquisa").equals("") || request.getParameter("nome_pesquisa") != null){
        try {
            List<Usuario> usuarios = this.dao.search(request.getParameter("nome_pesquisa"));
            String json = new Gson().toJson(usuarios);

            response.setContentType("application/json");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write(json);
        } catch (Exception ex) {
            Logger.getLogger(UsuarioController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

JSP:

<form class="col-md-10">
                <div class="input-group">
                    <input class="form-control border-secondary py-2" type="search" id="nome_pesquisa" name="nome_pesquisa" placeholder="Pesquisar...">
                    <div class="input-group-append">
                        <button class="btn btn-outline-secondary" type="submit" id="pesquisar" name="pesquisar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>
                </div>
            </form>

Return obtained:

    
asked by anonymous 15.11.2018 / 20:35

1 answer

1

Maybe it's because you forgot to deny the condition

 !request.getParameter("nome_pesquisa").equals("")
    
15.11.2018 / 23:34