概述
Ajax跨域是前端开发中常见的问题,本文描述了以Google浏览器Chrome作为客户端和以Tomcat作为Web服务器的情况下的解决办法。
问题现象
当出现跨域访问的时候ajax通常会报类似如下错误:
XMLHttpRequest cannot load http://192.168.2.12:8001/oss/api/version/check. No ‘Access-Control-Allow-Origin’ header is present on the requested re
这篇文章主要给大家介绍了关于Django跨域请求问题解决的相关资料,文中介绍的实现方法包括:使用django-cors-headers全局控制、使用JsonP,只能用于Get方法以及在views.py里设置响应头,只能控制单个接口,需要的朋友可以参考下。
使用Django在服务器端写了一个API,返回一个JSON数据。使用Ajax调用该API:
但是,Chrome浏览器提示错误:
No ‘Access-Control-Allow-Origin’ header is present on the
一、什么是跨域问题
在一个服务器A里放置了json文件,另一个服务器B想向A发送ajax请求,获取此文件,会发生错误。
Chrome提示:
XMLHttpRequest cannot load ******. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
这就是跨域问题。解决方案有不少,比较好