Passing POST Asynchronous, array returns 0

Asked

Viewed 29 times

0

I’m trying to pass the data from one Form to another page: My Option is doing a query in Mysql to return the values within the option options.

<form method="POST" action="">
                  <div class="form-row">
                    <div class="form-group col-md-6">
                      <label>Nome da Impressora</label>
                      <?php 
                      //include "config.php";
                      //clausula sql
                      $sql = "SELECT * FROM bd_print order by id";

                      //executa a clausula sql
                      $result = mysqli_query($con, $sql)or die("Falha na execução da instrução SQL!");
                      ?>
                         <select name="nome_imp" class="form-control" id="tabela">  
                            <option select> Selecione ...</option>
                         <?php

                            while($dados = mysqli_fetch_array($result))
                            {
                                echo "<option value='".$dados['nome']."'>".$dados['nome']."</option>";
                            }

                            echo "</select>";

                        ?>
                         </select>
                    </div>

                  </div>
                  <button type="button" id="remover" class="botao btn btn-primary" />Remover</button>
                </form>

Follow the code responsible for running the php script;

$(".botao").click(function(){
    var vNome = $("#nome_imp").val();

        $.ajax({
            type: "POST",
            data: { 
            nome_imp : vNome            

            },

            url: "function/rmv_func.php",
            dataType: "html",

            success: function(result){
                $("#respostabla").html('');
                $("#respostabla").append(result);
            },
            beforeSend: function(){
                $('#resposta').css({display:"block"});
            },
            complete: function(msg){
                $('#resposta').css({display:"none"});

            }
        });

    });

What happens is that the return of the post is "Undefined index "nome_imp", that is, the post is not being passed. If I do the action directly through FORM, it passes the POST. I believe my mistake is in the syntax of ajax, but I’m not able to identify where.

2 answers

0


It wouldn’t be because you’re trying to fetch the input with the query #nome_imp, being that his id is actually tabela?

Try to change the

var vNome = $("#nome_imp").val();

for

var vNome = $("#tabela").val();
  • Correct, it was a primary mistake of mine not to notice it, but thank you for making time available and show me, thank you !!!

0

Note that your select has the name = nome_imp and id = tabela. When you pass the post through the direct form, PHP identifies the correct name

You should wear it on your jQuery:

var vNome = $("#tabela").val();
  • Correct too, thanks for the feedback !!!

Browser other questions tagged

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