I am trying to test a call to my local Django development server. This is an AJAX call that returns a JSON object. The Django view does this:
return JsonResponse(response, safe=False)
I test this by launching the Django server (which runs the back end) and then launching my browser and opening the HTML page I have modified. These pages are not served by Django.
In Firefox, I can make the ajax call on the page. It returns the correct data, with the correct MIME type.
In Chrome, I can not. I get the following error:
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://localhost:8000/dataload/alljson with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
I have tried to search for the solution to this problem. I've checked this question, but the suggestion to clear my cache doesn't do anything. I've also found suggestions that involve using django-cors-headers
, but this is CORB (not CORS). Nonetheless, I've installed corsheaders
and set CORS_ORIGIN_ALLOW_ALL = True
to eliminate that as a possibility.
My MIDDLEWARE
setting has this
MIDDLEWARE = [
...
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
...
]
The response headers I get in Firefox are:
Content-Length 12827
Content-Type application/json
Date Wed, 06 Feb 2019 18:38:03 GMT
Server WSGIServer/0.2 CPython/3.6.7
Vary Origin
X-Frame-Options SAMEORIGIN
I am calling http://localhost:8000/dataload/alljson
. If I call http://localhost:8000/dataload/alljson/
(with the trailing slash), I get a 404.
Still no dice.
How can I get Chrome to allow the response from my development Django server for this ajax call?