0
Basically I need to use a Javascript variable in a php to later register, in the database. I have a boot <a href="carrinho.php"><button id="btnTestar">TESTE</button></a>
that leads to the cart page.php.
On the cart page.php I want to receive the variable.
$teste = $_POST['teste'];
ajax code
$(document).ready(function () {
$("#btnTestar").click(function(){
var teste = "testando";
$.ajax({
type: "POST",
url: "carrinho.php",
data:{'teste':teste},
success: success,
dataType: dataType
});
});
});
I don’t know what’s wrong because I’ve never used ajax before so I’m in doubt.
the error that appears on the php page is thisNotice: Undefined index: teste
Try to pass
teste: teste
instead of'teste': teste
– Francisco
Try modifying in AJAX: date: test
– Victor Hugo