The error message "Uncaught TypeError: Cannot read properties of undefined (reading 'headers')" suggests that the window.axios.defaults.headers.common object is undefined. This error occurs when you try to access a property of an undefined object.
To fix this issue, you need to make sure that the window.axios.defaults.headers.common object is defined before trying to access its properties. One way to do this is by checking if the object exists and creating it if it doesn't.
Here's an example of how you can modify the code to handle this error:
if (typeof window.axios.defaults.headers.common === 'undefined') {
window.axios.defaults.headers.common = {};
}
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
By checking if window.axios.defaults.headers.common is undefined, we can create an empty object if it doesn't exist. This ensures that the subsequent assignment to the X-Requested-With header property doesn't throw an error.
Make sure to place this modified code before any other code that relies on the window.axios.defaults.headers.common object to avoid any further errors.
I hope this helps! Let me know if you have any further questions.