skip to Main Content

student_id having a value of 0001. It shows the error

"Uncaught ReferenceError: studentId is not defined"

$.ajax({
    url: "student_info.php",
    method: "post",
    data: {
      studentId: student_id
    },
    success: function (data, status) {
      console.log(studentId);
    },
  });

console.log should display the value of ‘0001’.

2

Answers


  1. it’s because studentId passed as json key to student_info.php if you want get student id you can use student_id

    Login or Signup to reply.
  2. Look at your code

    $.ajax({
        url: "student_info.php",
        method: "post",
        data: {
          studentId: student_id
        },
        success: function (data, status) {
          console.log(studentId);
        },
      });
    

    studentId isnt a variable it should be something akin to

          console.log(data....studentId);
    
    

    studentId is contained in your data object. That being said it would be good to show the full code and also log the data and status, that way the question is more reproduce-able and we ensure there are no other issues

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search