Why is it that my javascript is not executing well? I used the sweetalert that pops-up but by then it is not triggering when i click the button

// Perform AJAX request
$.ajax({
url: ‘/Account/Register’,
method: ‘POST’,
data: formData,
enctype: ‘multipart/form-data’,
processData: false,
contentType: false,
success: function (response, status, jqXHR) {
console.log(response); // Log the response to see what the server returns

     // Check if the response contains a success property
     if (response.success) {
         // Display success pop-up
         Swal.fire({
             title: 'Registration Successful',
             icon: 'success',
             showConfirmButton: true
         }).then(function () {
             // Redirect to the appropriate page
             window.location.href = '/Home/Index';
         });
     } else {
         // Handle cases where registration failed
         Swal.fire({
             title: 'Registration Failed',
             text: response.message || 'An error occurred during registration.',
             icon: 'error',
             showConfirmButton: true
         });
     }
 },
 error: function (jqXHR, textStatus, errorThrown) {
     // Log the error for debugging
     console.error(textStatus, errorThrown);

     // Display error message using SweetAlert
     Swal.fire({
         title: 'Registration Failed',
         text: 'An error occurred during registration.',
         icon: 'error',
         showConfirmButton: true
     });
 }

});