我無法從Rescue Time API檢索數據。我正在使用jQuery get()方法在JavaScript文件中發出請求。下面來看看在JavaScript的相關API GET請求:訪問API時出現「Access-Control-Allow-Origin」請求錯誤
$.get('https://www.rescuetime.com/anapi/data?key=########################&format=json&restrict_kind=overview', function(data) {
// callback function code...
});
的 「key = ########################」是包含我的API密鑰的參數。
運行腳本時(本地或在我的個人域名),我收到一個跨源錯誤:
XMLHttpRequest cannot load https://www.rescuetime.com/anapi/data?key=########################&format=json&restrict_kind=overview . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
據我所知,這種情況正在發生,因爲我要求的某些內容在不同的域比發出AJAX請求的人要多。話雖如此,我該如何解決這個問題?我已閱讀CORS MDN documentation,但無法解碼我需要遵循的可解決此問題的可操作步驟。
我需要一些可操作步驟。
的https://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy – abagshaw
可能重複的可能的複製[途徑來規避同源政策(https://開頭stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – abagshaw
他們將需要把它放在他們的最終....可以;做T從客戶端代碼什麼。 – epascarello