Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda