AJAX call not initializing for non-admins in WordPress

There are several potential reasons for this issue:

Permissions: Non-admin users may not have the necessary permissions to access the admin-ajax.php file, which is being called in your AJAX request. Make sure that the required permissions are set for the user roles other than admin.

Authentication: Non-admin users may not be authenticated to access the admin-ajax.php file. You may need to check if the user roles other than admin have the necessary authentication to access the AJAX endpoint.

Capability check: You may have implemented a capability check in your server-side code that restricts the AJAX functionality to only admin users. Make sure that the capability check allows the required user roles to access the AJAX endpoint.

URL issue: The URL used in your AJAX request () may not be correct for non-admin users. Make sure that the URL is valid and accessible for all user roles.

Error handling: Your error handling in the AJAX request is incomplete (alert statement is incomplete). Make sure that you have proper error handling in place, such as logging errors to the server or displaying meaningful error messages to users, to help diagnose and resolve the issue.

Plugin/Theme conflict: It’s possible that there could be a conflict with a plugin or theme that is affecting the AJAX functionality for non-admin users. Try deactivating plugins or switching to a default theme to see if the issue persists.

You may need to investigate and debug further to identify the specific issue. Checking server-side code, permissions, authentication, capability checks, URLs, and error handling can be helpful in resolving this issue.