JavaScript JS 跨域問題
HTTP 錯誤 405 - 用於訪問該頁的 HTTP 動做未被許可
HTTP 錯誤 405.0 - Method Not Allowed
Nginx 處理跨域問題、OPTIONS 方法的問題php
Method = "OPTIONS" | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT" | extension-method extension-method = token
解決辦法:跨域
在Nginx location 里加上以下代碼能夠解決js 請求跨域問題:spa
location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } if ($request_method = 'OPTIONS') { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Credentials true; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; add_header '*'; return 200; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' *; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header '*'; } if ($request_method = 'GET') { add_header 'Access-Control-Allow-Origin' *; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header '*'; }
}
code
注意,必須放在 location ... { ... }裏面才能用if條件判斷。blog