Ajax Undefined index

-5

Hello, could anyone help me please? I've been to several sites trying to resolve this problem.

The js code works perfectly, and $("#links").load( "buscas.php" ); loads, but the PHP code always gives the error:

  

Notice: Undefined index: searches in.

In my opinion, js is not able to send the data to the search.php, but the reason, I have no idea.

I do not know what else to do, I even decreased the code and I left this nonsense down here and still got the same error.

Js code

$(document).ready(function(){

    $("button").click(function(){

        botao = $(this).html();

        $.ajax({
            type:"POST",
            dataType:"HTML",
            url:"buscas.php",
            data: {tipo: botao},
            success: function(data){
            $("#links").load( "buscas.php" );

            }
        }); 

    });

});

PHP code (search.php)

if(isset($_POST['tipo'])){

    $tipo = $_POST['tipo'];

    echo "Botao ".$tipo." precionado";

}
else{
    echo "Variavel nao definida";
}
<!DOCTYPE html> 
<html> 
  <head> 
   <script src="js/jquery-3.0.0.min.js">

   </script> <script src="js/busca.js"> </script> 

   <title>Links</title> 

  </head> 

   <body>
 <button id='botao'>botao1</button><br>
 <button id='botao'>botao2</button><br>

      <div id="linksPainel">

         <div id="links"> 

         </div> 

      </div>

   </body> 

</html>

@WilliamNovak That was the only code I did not show. Sorry, I thought it would not matter.

<?php 
    require "dbPDO.php";

    if(isset($_POST['tipo'])){

        $tipo = $_POST['tipo'];

        $busca = $conect->prepare("SELECT * FROM link WHERE tipo = '".$tipo."' ORDER BY id DESC ");
        $busca->execute();

        echo "<h2>$tipo</h2>";
        while ($row = $busca->fetch(PDO::FETCH_ASSOC)) {
            # code...
            $nome = $row['nome'];
            $link = $row['link'];
            echo "<a href='$link' target='_blank'>$nome</a><br>";

        }
    }else{
        echo "Variavel nao definida";
    }

?>

There you go!

    
asked by anonymous 31.07.2016 / 22:15

1 answer

1

Your javascript is making 2 posts. Is it to do this? Not to mention that in the second it is not sending anything to buscas.php (where the error should occur). If the idea is to get the result of buscas.php according to the parameters received, try something like

$.post("buscas.php", {tipo: botao}, function(data){
    //Resultado após o post
});

If you want to use GET:

$.get("buscas.php", {tipo: botao}, function(data){
    //Resultado após o get
});

If you want to use the load method:

$("#links").load( "buscas.php", {tipo: botao} );
    
01.08.2016 / 20:21