A
A
Artem Prokhorov2021-06-14 12:35:57
JavaScript
Artem Prokhorov, 2021-06-14 12:35:57

How to remove No 'Access-Control-Allow-Origin' from CORS if there is no question mark in the URL?

This is probably strange, but my cors gives an access error only if fetch in js has a URL without a question mark. CORS is set up and my Vue project has access to the server.
It won't let you:

fetch('http://back.ru/role').then(res => { return res.json() })
        .then(data => { this.role = data.items });


And so it lets in:
fetch('http://back.ru/role?').then(res => { return res.json() })
        .then(data => { this.role = data.items });


Moreover, I tried to set it assuming that it may be necessary to explicitly specify the request method and only in this way the server will understand it (get, post, delete, put are available on the server). But no, even so, it gives this error as if localhost:8080 is not registered in Access-Control-Allow-Origin, but it is registered. And with a question mark, everything is ok. PS POST, PUT, DELETE requests do not require ? in the URL, there it looks something like this , since the CNC is enabled on the server and everything works. method: "GET"
http://back.ru/menu/4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-06-14
@Rsa97

In certain cases, the browser makes a preflight request . The resource is first requested using the OPTIONS method, which the browser expects to receive a 200 response with CORS headers set. And only if this request passed, then the main request is made.
Check that your server responds normally to OPTIONS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question