I'm currently using the API via javascript ajaxJavaScript AJAX calls and it all of a sudden stopped allowing CORS requests. I'm on localhost and I tried uploading my code to live and am still getting:
Access to XMLHttpRequest at 'https://api.stackexchange.com/2.2/search/advanced?pagesize=100&order=desc&sort=relevance&q=unit%20testing%20in%20react&answers=1&wiki=False&site=stackoverflow&key=g1ojUOeEFrEJKWLcC5yqhQ((' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Cross-Origin Read Blocking (CORB) blocked cross-origin response https://api.stackexchange.com/2.2/search/advanced?pagesize=100&order=desc&sort=relevance&q=unit%20testing%20in%20react&answers=1&wiki=False&site=stackoverflow&key=g1ojUOeEFrEJKWLcC5yqhQ(( with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
Access to XMLHttpRequest at
'https://api.stackexchange.com/2.2/search/advanced?pagesize=100&order=desc&sort=relevance&q=unit%20testing%20in%20react&answers=1&wiki=False&site=stackoverflow&key=g1ojUOeEFrEJKWLcC5yqhQ(('
from origin 'http://localhost:3000' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested
resource.
Cross-Origin Read Blocking (CORB) blocked cross-origin response
https://api.stackexchange.com/2.2/search/advanced?pagesize=100&order=desc&sort=relevance&q=unit%20testing%20in%20react&answers=1&wiki=False&site=stackoverflow&key=g1ojUOeEFrEJKWLcC5yqhQ((
with MIME type application/json. See
https://www.chromestatus.com/feature/5629709824032768 for more
details.
The API has stopped allowing CORS requestsThe API has stopped allowing CORS requests
API endpoints do not set Access-Control-Allow-Origin, so CORS requests failAPI endpoints do not set Access-Control-Allow-Origin, so CORS requests fail
If I switch out my ajax urlAJAX URL for something like api.github.com/users/:username
then I get a response.
Response header from api.stackexchange.comapi.stackexchange.com
:
vs Response header from api.github.comapi.github.com
:
Update 11/15/2019
It seems to work as normal again. I no longer get CORS errors or warnings.
According to this answer, it was due to SE porting their MVC to .NET core