我爲我的後端使用laravel並嘗試向jQuery發送請求到Instagram api,但我在Chrome瀏覽器檢查器中響應正常時收到此錯誤PHP Nginx沒有'訪問控制 - 允許 - 來源'錯誤
test?code=a3679b3…:1 XMLHttpRequest cannot load https://api.instagram.com/oauth/access_token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.
,這是我的代碼發送請求
$.ajax({
method: 'POST',
url: 'https://api.instagram.com/oauth/access_token',
data: {
client_id: "client_id",
client_secret: "client_secret",
grant_type: "authorization_code",
redirect_uri: "example.com",
code: "{{$code}}"
}
});
我試着在我的Nginx的default.conf
文件添加Access-Control-Allow-Origin
但沒有解決我的問題。我該如何解決它?
我覺得你可以按照這個鏈接。可能會有所幫助。 [http://stackoverflow.com/questions/6114436/access-control-allow-origin-error-sending-a-jquery-post-to-google-apis](http://stackoverflow.com/questions/6114436/ access-control-allow-origin-error-sending-a-jquery-post-to-google-apis) –