Jquery returns "0" in div

Asked

Viewed 138 times

0

I have a function ajaxForm that searches some data in the database and should return the HTML result in a div. The problem is that when inspecting the page the return is correct, but in div appears only the number "0". Someone can help?

Form:

<form class="form-inline" method="POST" id="pesquisa" action="">
            <fieldset>
                <div class="col-sm-8">
                    <div class="form-group">
                        <input type="btn" id="movimenta" name="movimenta" class="form-control" aria-describedby="basic-addon2">
                        <select class="form-control" id="galpao" name="local">
                            <option>Selecione o local</option>
                            <?php
                            while($linha = mysqli_fetch_assoc($galpao)){?>
                            <option value="<?php echo $linha['id']; ?>"><?php echo $linha['nome']; ?></option>
                            <?php }?>
                        </select>
                        <input type="submit" class="form-control" id="pesquisaGalpao" value="Pesquisar">
                    </div>
                </div>
            </fieldset>
        </form>

Div:

<div class="info">0</div>

Ajax code:

$(document).ready(function(){
    $('#pesquisa').ajaxForm({
        target:'.info',
        url:'sql.php',
        success: function(msg){
            $(".info").html(msg);
        }
    });
});

Return shown when inspecting the page:

<section class="panel col-lg-12">
        <table class="table table-striped table-bordered table-hover table-checkable order-column" id="">
        <thead>
            <tr>
                <th> Código</th>
                <th> Descrição </th>`

What the form sends:

movimenta:grampo
local:11

What returns from the sql.php page:

Código  Descrição   Galpão  Rua Coluna  Altura  Qtde    Lote    Validade    Movimentar
12345678901234  GRAMPO  Armazem 01  1   2   0   15
  • Is there a better way to detail what’s going on? If you inspect the element, what exactly is the content that appears? 0 appears on the rendered page?

  • Do you have any other element with that same class? Have you tried replacing it with a #id?

  • the Id #pesquisa is there? can put the entire code so that it is possible to better understand the problem?

  • I updated the question with the form code. I already replaced it with id and the same problem happens.

  • Responding to Anderson and Leornardo, yes, it is on the rendered page that 0 appears and I have no other element with this class. Also already replaced by id and the same problem happens.

  • Do not use the question to answer the problem. The answer field already has this purpose, so use it.

  • @Eduardo Again I will say: [en.so] is not a forum, so DO NOT use the question area to publish the answer. Make the [tour] as soon as possible and learn to use the site correctly to avoid any embarrassment.

  • Thanks @Andersoncarloswoss, I’ll find out the features.

Show 3 more comments

1 answer

0

You seem to be wearing this jQuery Form Plugin. If that’s the case, I’m surprised that you use option-based both the property target, that "... identifies the element to be updated with the server response", for a callback on the property success which populates the same element as the target is trying to update. Try using only one of the two - ordinarily, I would say to comment on success and maintain the target, but check the other possibility if the first does not work.

  • Wtrmute, your answer solved a problem that arose when I changed the code to .load. The post was sent twice. The way you went was much simpler and the result was great. I will update the code in the question. Thank you very much!

Browser other questions tagged

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