2
I’m trying to pass values through two variables in AJAX to a PHP file, but it’s not working. if I put data: { idUsuario: "5", idEscolha: "1", } right. What is wrong?
$(document).ready(function(){
$("#botao").click(function(){
var url = "InserirEscolha.php";
$.ajax({
var idUsuario = "5";
var idEscolha = "1";
type: 'post',
url: 'UpdateVisto.php',
data: { idUsuario: idUsuario, idEscolha: idEscolha, }
});
$.post(url, function(result) {
});
});
});
<?php
$idUsuario = $_POST['idUsuario'];
$idEscolha = $_POST['idEscolha'];
include "config_sistema.php";
$query = mysql_query("INSERT INTO usuario_escolha
(id_usuario, id_escolha)
VALUES('{idUsuario}','{$idEscolha}')");
if ($query){
header("Location: perfil.php?ID=$idUsuario");
}
?>
What code does not work
$.ajax
or the$.post
? the first example is right, you did not show in which example fails.– rray
$.ajax. When I use the variables idUsuario and idEscolha, it does not receive the values. If I enter the values directly without the right variables
– Rafael Gonçalves
Try to pass it off
data: {'idUsuario': idUsuario, 'idEscolha': idEscolha, }
– rray
Now it’s worked, thanks!
– Rafael Gonçalves