write via the input button

0

Colleagues.

I have the Tabs in Ajax template and thanks to our colleague DontVoteMeDown, I get through the button type button to change tabs, but how would I do it so that when changing tabs, I register the information of the previous tab in the bank? The registration in PHP / Mysql I know how to do, what is happening is that when changing tab, the input does not occur, only if I use submit . See below (I changed the code and it is registering in the database, but how do I pass the form values to jquery?):

     <script>
      $(function() {
        $( "#tabs" ).tabs();
          $("#btnComprar").on("click", function() 
                {
                  $.post("cadastrar_.php", // Cadastando OK
                              {
// Como faço para pegar os valores do formulário e jogar para o campo abaixo?
                             nome: "nome do usuário",
                               idade: "idade"
                  },
                        function(data, status){
                    //   alert("Data: " + data + "\nStatus: " + status);
                        });

                var indice = $('#tabs ul li a[href="#' + $(this).parent().prop("id") + '"]').parent().index();
                    $("#tabs").tabs("option", "active", (indice + 1));

                });
        $(".voltar").on("click", function() 
                {
                    var indice = $('#tabs ul li a[href="#' + $(this).parent().prop("id") + '"]').parent().index();              
                    $("#tabs").tabs("option", "active", (indice - 1));
                });
        });
      </script>

          <button type="button" id="btnComprar" class="proximo btn btn-success pull-right proximo" name="Valor" value="Comprar" style="margin-right: 10px" disabled="disabled"/><i class="fa fa-cart-plus"></i> Comprar </button>
    
asked by anonymous 28.09.2015 / 22:02

1 answer

1

Now there is no error, with this example you should be able to solve your problem, but study more JSON, it's worth it and my example is not the best yet.

file.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <form>
    <label>Nome
        <input id="nomeId" name="nome" >
    </label>
    <label>Nome novo
        <input id="nomeNovo" name="nomeNovo" >
    </label>
    <button type="button" id="enviar">Vai</button>
  </form>
    <div id="view"></div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script>$("#enviar").click(function(){
      var inputNome = $("#nomeId").val();

    $.ajax({
      type:"POST",
      url:"cadastrar.php",
      data:{"nome": inputNome},
      success:function(dados){
        var resposta = $.parseJSON(dados);
        $("#nomeNovo").val(resposta.nome+" Sobrenome");
      }
    });
  });
    </script>
</body>
</html>

cadastro.php

<?php
if($_SERVER['REQUEST_METHOD'] != "POST") {exit;}

echo json_encode($_POST);
?>
    
28.09.2015 / 23:22