On the same Laravel project, I have an API at localhost:8000/api
and a website at localhost:8000/admin
. When I send the following request from the website, which is supposed to return a list of partners in JSON, it returns a status 0:
let token = "e9Klj0...";
$.ajax({
url: "localhost:8000/api/partners",
headers: {
"Authorization": "Bearer "+token,
"Accept": "application/json",
},
success: function(res) {
console.log(res);
},
error: function(xhr) {
console.log(xhr.status);
}
});
According to the answers of this question, the different cases of status 0 are:
- unreachable URL: I don't think the problem comes from there, I can access
localhost:8000/api/partners
via Postman. - intercepted request by the ad blocker: I've disabled uBlock Origin, but it still won't work.
- interrupted request: I don't send any other request than that of AJAX.
- cross-site scripting: I think that's the most likely case but my API and my website run on the same webserver, and AJAX handles internal requests without dealing with the CORS.
How could I fix this problem?
Thank you for your help.