First Thing to know is that error code 422 means Validation Error.
This error occurs due to no data sending with the request. please try this code
$("#form_create_account").submit(function(e) {
e.preventDefault();
let formData = new FormData(this);
$.ajax({
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
url: $(this).attr('action'),
type: $(this).attr('method'),
data: formData,
contentType: false,
processData: false,
beforeSend: function() {
$('#createAccountBtn').html('Loading.....');
},
error: function(response) {
let formErrors = response.responseJSON.errors;
let htmlErrors = '<div class="invalid-feedback">';
if(formErrors.hasOwnProperty('email')) {
htmlErrors += formErrors.email[0];
}
if(formErrors.hasOwnProperty('password')) {
htmlErrors += formErrors.password[0];
}
if(formErrors.hasOwnProperty('password_confirmation')) {
htmlErrors += formErrors.password_confirmation[0];
}
if(formErrors.hasOwnProperty('cf-turnstile-response')) {
htmlErrors += formErrors.cf-turnstile-response[0];
}
$('.invalid-feedback').html(htmlErrors);
},
success: function(response) {
console.log(response);
$('#createAccountBtn').html('Account is created!');
},
});
});