DJANGO的API跨域实现
Ajax跨域请求报错:XMLHttpRequest cannot load ''. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' ' is therefore not allowed access.
这种错误如何解决?
一种是JSONP。
一种是DJANGO上的第三方插件:django-cors,
相当URL:
http://stackoverflow.com/questions/38649170/django-cors-x-firephp-version
https://github.com/ottoyiu/django-cors-headers
基本设置:
django-cors-headers
A Django App that adds CORS (Cross-Origin Resource Sharing) headers to responses.
Although JSON-P is useful, it is strictly limited to GET requests. CORS builds on top of XmlHttpRequest to allow developers to make cross-domain requests, similar to same-domain requests. Read more about it here:http://www.html5rocks.com/en/tutorials/cors/