Problem loading jquery load

Asked

Viewed 62 times

0

I’m having trouble loading these values in the jquery load.

Follows the code.

Javascript:

 $('.buscando').click(function(){

            var id = document.getElementById('campo1').value;

            $("#cliente1").load('/wbahd/servico_servlet?acao=buscar&busca='+id);
          });

This code does the action takes the parameter but does not load the page.

HTML:

 <div class="form-group">
        <label for="busca">Nome Servico*:</label> <input id="campo1" type="text" class="form-control" placeholder="Insira um nome para busca">
    </div>
    <a href="#"  class="btn btn-default btn-cadastrar-btn buscando">Buscar</a>

    </div>

Obg.

  • Open the console and see if an error has occurred, also make sure there is the element <div id="cliente1"></div>

1 answer

2


The load() method has two other optional parameters that we can use, if necessary, that are specified with the typical property notation and values of jQuery.

For example: {acao: "buscar", busca: id} with this code we would be sending to the page the data action and quest, with the values "fetch" and id, id being the variable with value passed by input. This data travels in the URL, by the "POST".

Script

$(document).ready(function(){
    $(".buscando").click(function(evento){
        evento.preventDefault();
        var id = $('#campo1').val();
        $(".cliente1").load("/wbahd/servico_servlet", {acao: "buscar", busca: id}, function(){
        });
    });
})

HTML

<div class="cliente1"></div>
<div class="form-group">
    <label for="busca">Nome Servico*:</label> <input id="campo1" type="text" class="form-control" placeholder="Insira um nome para busca">
    <a href="javascript:void(0)" class="btn btn-default btn-cadastrar-btn buscando">Buscar</a>
</div>
  • Obg leo . It worked perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.