pass variables from AJAX to PHP

2

I'm trying to pass values through two variables in AJAX to a PHP file, but it's not working. if I put date: {idUsuario: "5", idChoose: "1",} sure. 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");
}
?>
    
asked by anonymous 24.10.2015 / 23:45

1 answer

1

You need to set the uploaded parameters, in that case add quotation marks names so that they are identifiable in php.

data: { 'idUsuario': idUsuario, 'idEscolha': idEscolha, }

If left in the form below, php will receive the post with parameters named 5 and 1 instead of idUsuario and idEscolha .

data: { idUsuario: idUsuario, idEscolha: idEscolha, }
    
25.10.2015 / 00:13