我最近將我的網站切換爲使用HTTPS。我使用Laravel作爲php框架。在開始時,我遇到了一個問題,我會得到一個「Origin-null不被Access-Control-Allow-Origin允許」。錯誤,但那時我已經固定,通過在我的filters.php使用此:HTTPS ajax請求
App::before(function($request)
{
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
});
的是Ajax請求:
$.ajax({
type: 'GET',
url: '/media/search/',
data: { 'q':search_string },
success: function(d) { }
});
現在,而不是跨源錯誤我得到一個重定向我的登錄頁面,而不是應該加載的內容。我認爲它與Laravel擁有的CSRF令牌實現有關,但我不確定應該將該令牌添加到請求還是我如何修復它。任何人有任何建議?
編輯:
如果我沒有在我的filter.php這些頭功能我得到這個錯誤:
XMLHttpRequest cannot load http://website.com/media/search?&q=500 . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' https://website.com ' is therefore not allowed access.
這個我已經着手使用這個調用,而不是後:
$.ajax({
type: 'GET',
url: 'https://website.com/media/search/',
data: { 'q':search_string },
success: function(d) { }
});
但仍沒有運氣
你是不是做跨域調用在這裏。 'Access-Control-Allow-Origin'不是必需的。 – mithunsatheesh 2014-10-07 12:28:30
請參閱我的編輯,我無法弄清楚如何在ajax調用上強制https。我會在我的電話中放入https:// website/search /',但它仍然會呼叫http – 2014-10-07 12:32:15
http <-> https被視爲跨域;使用相同的協議爲ajax調用 – 2014-10-07 12:33:14