Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
Passing variable from JS using ajax to PHP undefined variable

I want to pass variable rating_index to the PHP code and send to database. Rating_index is set I'll not pass the code here because it is long, but right before AJAX i console.log(rating_index) and it has value(int). Add-review is a button that after click should send variable. In js script I am using AJAX :

$('#add-review').click(function(){
     $.ajax({
        url:"rating-data.php",
        method:"POST",
        data: {
            rating_index: rating_index
        },
        success:function(data)
        {
           
            console.log(data);
        }
    })
}

in my php file rating-data.php:

<?php 
    include 'connection.php';
    echo "work";
    echo $_POST["rating_index"];
?>

I got a console.log ('work') from PHP file and this error: Notice: Undefined index: rating_index in /Applications/XAMPP/xamppfiles/htdocs/bookwarm-app/rating-data.php on line 4

So it is getting my to php page but the variable are not passing correctly.

I was trying everything and I have no idea what is wrong and why this variable is undefined in php file. Thanks for any clue

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is the problem in your code, sir

$user_name = $_GET["user_name"];
$user_rating = $_GET["rating_index"];
$user_review = $_GET["user_review"];

you're doing a $_POST request from Ajax and in php file you're getting values from $_GET.....?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda