my Ajax does not show the swal on success or error meaning when am done adding a book and click Add nothing happens despite the PHP working fine. Correct the ajax code: FORM CODE: <div class="modal fade" id="modalForAddGEDBook" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-xl" role="document">
    <form class="refreshFrm" id="addGBPostFrm" action="" method="post" enctype="multipart/form-data">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title">Create a New GED - HiSET Book</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <div class="col-md-12">
            <div class="form-group">
              <label>Title</label>
              <input type="" name="title" id="title" class="form-control" placeholder="enter title" autocomplete="off">
            </div>

            <div class="form-group">
              <label>Category</label>
              <select class="form-control" name="cat_id" required="">
                <option value="">No category selected</option>
                <?php
                $selAllCategories = $conn->query("SELECT * FROM ged_book_categories ORDER BY id DESC");
                while ($selAllCategoriesRow = $selAllCategories->fetch(PDO::FETCH_ASSOC)) { ?>
                  <option value="<?php echo $selAllCategoriesRow['id']; ?>"><?php echo $selAllCategoriesRow['category']; ?></option>
                <?php }
                ?>
              </select>
            </div>

            <div class="form-group">
              <label>Content</label>
              <textarea class="form-control editor" id="editGBPost" name="content"></textarea>
            </div>

            <div class="form-group">
              <label>Select Course</label>
              <select class="form-control" name="courseSelected" id="coursesGBSelected">
                <option value="0">Select Course</option>
                <?php
                $selCourse = $conn->query("SELECT * FROM ged_course_tbl ORDER BY cou_id DESC");
                if ($selCourse->rowCount() > 0) {
                  while ($selCourseRow = $selCourse->fetch(PDO::FETCH_ASSOC)) { ?>
                    <option value="<?php echo $selCourseRow['cou_id']; ?>"><?php echo $selCourseRow['cou_name']; ?></option>
                  <?php }
                } else { ?>
                  <option value="0">No Course Found</option>
                <?php }
                ?>
              </select>
            </div>

            <div class="form-group">
              <label>Select Subject</label>
              <select class="form-control" name="subjectSelected" id="subjectsGBSelected">
                <option value="0">Select Subject</option>
              </select>
            </div>

            <div class="form-group">
              <label>Book Status</label>
              <div class="form-check">
                <input class="form-check-input" type="radio" name="bookStatus" id="bookGBStatus1" value="active" checked>
                <label class="form-check-label" for="bookGBStatus1">
                  Active
                </label>
              </div>
              <div class="form-check">
                <input class="form-check-input" type="radio" name="bookStatus" id="bookGBStatus2" value="draft">
                <label class="form-check-label" for="bookGBStatus2">
                  Draft
                </label>
              </div>
            </div>

            <div class="modal-footer">
              <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              <button type="submit" class="btn btn-primary">Add Now</button>
            </div>
            </fieldset>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>

<script>
  $(document).ready(function() {
    $('#coursesGBSelected').change(function() {
      var courseId = $(this).val();
      $.ajax({
        url: 'query/getGEDSubjects.php', // Update the URL to point to the correct location of getSubjects.php
        method: 'POST',
        data: {
          courseId: courseId
        },
        success: function(data) {
          $('#subjectsGBSelected').html(data);
        },
        error: function() {
          $('#subjectsGBSelected').html('<option value="0">An error occurred</option>');
        }
      });
    });
  });
  //ADD POST
  CKEDITOR.replace('editGBPost', {
    extraPlugins: 'uploadimage',
    uploadUrl: 'includes/upload.php?type=Files&responseType=json&_token=',
    filebrowserImageUploadUrl: 'includes/upload.php',
    filebrowserUploadMethod: 'form',
    clipboard_handleImages: true,
    indent: false,
    breakBeforeOpen: true,
    breakAfterOpen: false,
    breakBeforeClose: false,
    breakAfterClose: true
  });
</script>   AJAX: // Add GED HiSET BOOK 
$(document).on("submit", "#addGBPostFrm", function (e) {
  e.preventDefault();
  CKEDITOR.instances['editGBPost'].updateElement();
  $.ajax({
    url: 'query/addGBPostExe.php',
    type: "post",
    data: new FormData(this),
    contentType: false,
    processData: false,
    success: function (data) {
      if (data.res === "exist") {
        Swal.fire({
          title: "Already Exist",
          html: data.msg + " Book Title already exists",
          icon: "error"
        });
      } else if (data.res === "success") {
        Swal.fire({
          title: "Success",
          html: data.msg + " Book Added Successfully",
          icon: "success"
        }).then(function () {
          $('#addGBPostFrm')[0].reset();
          CKEDITOR.instances['editGBPost'].setData('');
          refreshDiv();
        });
      }
    },
    error: function (jqXHR, textStatus, errorThrown) {
      var errorData = jqXHR.responseJSON;
      Swal.fire({
        title: "Error",
        html: errorData.msg,
        icon: "error"
      });
    }
  });
});     PHP: <?php
include("../../../conn.php");

extract($_POST);

$selCourse = $conn->query("SELECT * FROM ged_books_tbl WHERE gu_title='$title' ");

if ($courseSelected == "0") {
  header('Location: ../home.php?page=manage-ged-books&error=No course selected.');
  $res = array("res" => "failed", "msg" => "No course selected.");
  exit();
} else if ($subjectSelected == "0") {
  header('Location: ../home.php?page=manage-ged-books&id=' . $courseSelected . '&error=No subjects selected.');
  $res = array("res" => "failed", "msg" => "No subjects selected.");
  exit();
} else if ($selCourse->rowCount() > 0) {
  header('Location: ../home.php?page=manage-ged-books&id=' . $courseSelected . '&error=Book Title already exists.');
  $res = array("res" => "exist", "msg" => $title);
  exit();
} else if ($bookStatus == "0") {
  header('Location: ../home.php?page=manage-ged-books&id=' . $courseSelected . '&error=Book status not set');
  $res = array("res" => "failed", "msg" => "Book status not set");
  exit();
} else {
  try {
    $insExam = $conn->query("INSERT INTO ged_books_tbl (gu_title,cat_id,gu_content,cou_id,sub_id,gu_status) VALUES('$title','$cat_id','$content','$courseSelected','$subjectSelected','$bookStatus')");
    // success handling
  } catch (PDOException $e) {
    $res = array("res" => "failed", "msg" => "System error: " . $e->getMessage());
    echo json_encode($res);
    exit();
  }
  if ($insExam) {
    $res = array("res" => "success", "msg" => $title);
    header('Location: ../home.php?page=manage-ged-books&id=' . $courseSelected . '&success=Book added Successfully');
    exit();
  } else {
    $res = array("res" =>"failed", "msg" => "System error. Try again later.");
    header('Location: ../home.php?page=manage-ged-books&id=' . $courseSelected . '&error=System error. Try again later.');
    exit();
  }
}

header("Content-Type: application/json");
echo json_encode($res);
?>