因为jquery禁止经过ajax进行跨域请求,因此在经过ajax请求另一个不一样域名服务api的时候会报错:“No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access”
python
最简单的两个解决办法:jquery
一、在django中return的时候设置nginx
def xxxxx(request): .... resp = HttpResponse(json.dumps({'code':code,'msg':msg,'data':data},ensure_ascii=False)) resp["Access-Control-Allow-Headers"] = "*" return resp
二、在nginx中设置ajax
add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS;