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!