因爲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;