how are you resolving the URL to call and have you viewed source on your ajax code to see what URL it is calling?
403 errors with RESTful methods using AJAX on shared host
I am trying to deploy a Laravel project on a shared hosting space running apache. The following problem occurs only for the website running on the shared host, on my localhost environment (using nginx to serve my site) everything runs without any errors.
So fwith regards to the site running on the shared hosting: the problem I am running into is that for some reason any 'DELETE', 'PUT' etc. requests using AJAX result in a 403 forbidden error. If I use a normal form submit instead of the AJAX call, every request seems to be handled just fine.
So for deleting, I use the following AJAX snippet:
...
$.ajax({
method: 'DELETE,
url: path/to/my/controller,
headers: {
'X-CSRF-TOKEN': token
},
...
});
...
which, as said before, is working fine on my local setup, but results in a 403 error on my shared host. Hence, I am relatively sure it can't have anything to do with not passing in the token or not doing any method spoofing.
One thing to mention is that on my shared hosting I have installed my Laravel app in the private_html/test directory and I have copied the content of the Laravel public folder to the public_html/test folder on the hosting server and I have adjusted the two paths in the index.php accordingly. This seems to work, since I can visit and browse the different pages of the site just fine.
I am beginning to suspect that I might need to add/revise the .htaccess file in the public Laravel folder somehow, but I wouldn't know how. Is there anyone who has faced a similar issue?
So I figured it out in the end. Still absolutely no idea why it worked perfectly fine on my localhost and not on the shared hosting, but all I needed to do in the end was to change my AJAX call from
$.ajax({
method: 'DELETE',
data: { _method: 'DELETE, _token: token },
...
});
to
$.ajax({
method: 'POST',
data: { _method: 'DELETE, _token: token },
...
});
Please or to participate in this conversation.