База данных обновлена, и электронное письмо отправлено, но вместо сообщения об успехе браузера Mozilla Firefox выдается ошибка - PullRequest
0 голосов
/ 25 марта 2019

У меня проблема в Mozilla Firefox, из-за которой часть AJAX предупреждает об ошибке вместо сообщения об успехе, когда я одобряю назначение на роль лектора. Это не происходит в Chrome, а также Edge. Когда я попытался проверить сеть на предмет ответа, для Mozilla Firefox ничего не вышло, и предупреждение автоматически закрылось. Тем не менее, электронная почта может быть отправлена ​​получателю, и база данных обновляется независимо от веб-браузеров. Я уже пытался проверить ответ с помощью var_dump в файле PHP, а также JSON.stringify () в части AJAX, чтобы проверить данные, переданные обратно, но не удалось. У меня есть три разных файла, связанных друг с другом для утверждения назначения.

i) ajax-Approve-detail-назначению * <?php require ("global-include.php"); if (isset($_POST['appointment_id'])) { try { $fetch_query = "SELECT * FROM appointment LEFT JOIN users AS student ON appointment.student_id = student.username LEFT JOIN course_field AS field ON appointment.field = field.field_id WHERE appointment.lecturer_id = :lecturer AND appointment_id = :appointment_id"; $stmt = $db->prepare($fetch_query); $stmt->bindParam(':lecturer', $_SESSION['username']); $stmt->bindParam(':appointment_id', $_POST['appointment_id']); $stmt->execute(); while($data = $stmt->fetch(PDO::FETCH_ASSOC)) { $appointment_id = $data['appointment_id']; $appointment_type = $data ['appointment_type']; $appointment_date = $data['appointment_date']; $appointment_time = $data['appointment_time']; $name = $data['name']; $email = $data['email']; $venue = $data['venue']; $remarks = $data['remarks']; $field_name = $data['field_name']; } } catch(PDOException $e) { echo $e->getMessage(); } } ?> <input type='hidden' value="<?php echo $appointment_id; ?>" name='appointment_id' id='appointment_id' /> <input type='hidden' value="<?php echo $appointment_type; ?>" name='appointment_type' id='appointment_type' /> <input type='hidden' value="<?php echo $appointment_date; ?>" name='appointment_date' id='appointment_date' /> <input type='hidden' value="<?php echo $appointment_time; ?>" name='appointment_time' id='appointment_time' /> <input type='hidden' value="<?php echo $name; ?>" name='name' id='name' /> <input type='hidden' value="<?php echo $venue; ?>" name='venue' id='venue' /> <input type='hidden' value="<?php echo $email; ?>" name='student_email' id='student_email' /> <input type='hidden' value="<?php echo $remarks; ?>" name='remarks' id='remarks' /> <input type='hidden' value="<?php echo $field_name; ?>" name='field_name' id='field_name' /> <?php // Retrieve the columns from the database to get lecturer name $sql = "SELECT username, name FROM users WHERE user_id = :user_id"; $stmt = $db->prepare($sql); if ($stmt->execute(array('user_id' => $_SESSION['user_id']))) { while($row = $stmt->fetch()) { //fetch the rows $username = $row['username']; $name = $row['name']; echo " <input type='hidden' name='lecturer_name' id='lecturer_name' value='". $row['name'] ."' /> <input type='hidden' name='lecturer_username' id='lecturer_username' value=". $row['username'] ." /> "; } } ?> <p>Are you sure you want to approve the appointment with this student?</p> ii) ajax-Approve-assign.php (этот файл содержит PHPMailer и запрос на обновление базы данных)

<?php
    require ("global-include.php");
    require ('PHPMailer/PHPMailerAutoLoad.php');
    require ('PHPMailer/smtp-credentials.php');


    if (isset($_POST['appointment_id']))
    { 
        try 
        {
          //fetch data
          //vardump($_POST['appointment_id']);
          //$appointment_id = $_POST['appointment_id'];
          $appointment_type = $_POST ['appointment_type'];
          $appointment_date = $_POST['appointment_date'];
          $appointment_time = $_POST['appointment_time'];
          $name = $_POST['name'];
          $venue = $_POST['venue'];
          $remarks = $_POST['remarks'];
          $field_name = $_POST['field_name'];
          $lecturer_name = $_POST['lecturer_name'];
          $student_email= $_POST['student_email'];

          $approve_appointment_query = "UPDATE appointment SET appointment_status='Approved' WHERE appointment_id= :appointment_id";
          $approve_statement= $db->prepare($approve_appointment_query);
          $approve_statement->bindParam(':appointment_id', $_POST['appointment_id']);
          $approve_statement->execute();

          //die($approve_statement);

          //PHPMailer set up      
          $approve_output="<strong>Greetings from STULEC,</strong> <br/>
          <p>Dear " . $name . ",  your appointment with the lecturer, " . $lecturer_name . ", has been approved. </p>
          The appointment details are such as below: <br/>
            <ul>
              <li>Appointment Type: ". $appointment_type ."</li>
              <li>Appoinment Date: ". $appointment_date ."</li>
              <li>Appointment Time: ". $appointment_time ."</li>
              <li>Venue: ". $venue ." </li>
              <li>Course Field: ". $field_name ." </li>
              <li>Remarks: ". $remarks . "</li>
            </ul>
          </p>
          <p>Please attend the appointment on time. If you wish to change the time of the the appointment, please login into STULEC and reschedule as fast as possible. Thank you.</p>";

          $mail = new PHPMailer;
          $mail->isSMTP();                                // Set mailer to use SMTP
          $mail->Host = 'smtp.gmail.com';             // Specify main and backup SMTP servers
          $mail->SMTPAuth = true;                   // Enable SMTP authentication
          $mail->Username = EMAIL;              // SMTP username
          $mail->Password = PASS;               // SMTP password
          $mail->SMTPSecure = 'tls';                    // Enable TLS encryption, `ssl` also accepted
          $mail->Port = 587;                        // TCP port to connect to

          $mail->setFrom('stulecappointmentsystem@gmail.com', 'STULEC');  //From sender
          $mail->addAddress( $student_email , $name);  // Add a recipient
          $mail->isHTML(true);                    // Set email format to HTML

          $mail->Subject = 'STULEC | Approval of Appointment from Lecturer';
          $mail->Body    =  $approve_output;
          $mail->CharSet = 'utf-8';
          $mail->ContentType = 'text/html';  


          if (($approve_statement->execute()) && $mail->send())
          {
              echo 'The appointment is approved and an email has been sent to the student.';
          } 
          else 
          {
              echo 'Error: The appointment cannot be approved and an email has been sent to the student.';
          }

          $data = $approve_statement->fetchAll();
          echo json_encode($data); 

        }
        catch(PDOException $e)
        {
          echo $e->getMessage();
        }  
    } 
    else
    {
        echo 'Nothing is approved';
    }
?>

iii) lecturer-view-pending-meeting.php (этот файл содержит части AJAX и JQuery)

  <script>
  $(document).ready(function()
  {
    //fetch details that want to be approved
    $(document).on('click','.approve_data', function()
    {
      var appointment_id = $(this).attr('id');
      //var appointment_id = $("#appointment_id").val();
      $.ajax({
        async: true,
        url: "ajax-approve-detail-appointment.php",
        type:"post",
        data:{appointment_id:appointment_id},
        success:function(data)
        {
          $("#approve_details").html(data);
          $("#approveModal").modal('show');
        }
      });
    })

    //approve appointment
    $(document).on('click','#btnApprove', function()
    {
      var appointment_id = $("#appointment_id").val();
      var appointment_type = $("#appointment_type").val();
      var appointment_date = $("#appointment_date").val();
      var appointment_time = $("#appointment_time").val();
      var name = $("#name").val();
      var venue = $("#venue").val();
      var remarks = $("#remarks").val();
      var field_name = $("#field_name").val();
      var lecturer_name = $("#lecturer_name").val();
      var student_email = $("#student_email").val();

      $.ajax({
        url: "ajax-approve-appointment.php",
        type:"post",
        data:{appointment_id:appointment_id, appointment_type:appointment_type, appointment_date:appointment_date, appointment_time:appointment_time, name:name, venue:venue, remarks:remarks, field_name:field_name, student_email:student_email, lecturer_name: lecturer_name},
        success:function(data)
        {
          alert('The appointment with this student is successfully approved.');
          $("#approveModal").modal('show');
          location.reload();
        },
        error: function(data) 
        {
          //JSON.stringify(data);
          alert('Error: The appointment with this student cannot be approved!');
          $("#approveModal").modal('show');
          location.reload();
        }
      });
    })

  });
  </script>

Из ajax-appprove-detail-meeting.php сетевой ответ выглядит следующим образом: enter image description here

Из ajax-Approve-assign.php сетевой ответ отсутствует: enter image description here

Вот сеть для параметров для ajax-Approve-assign.php: enter image description here

Надеюсь, что вы можете указать мне, в чем проблема, потому что я на самом деле не эксперт в AJAX и JQuery. Спасибо.

...