GitPage 上$.getJSON讀取不到json,出現 404 ERROR

GitPage 上$.getJSON讀取不到json,出現 404 ERROR

我將content.json檔放在Localhost測試正常後,才push到github,接著開啟GitPage,發現沒辦法實行AJAX功能,讀取不到我的content.json資料

Consolo.log顯示

  • Failed to load resource: the server responded with a status of 404 ()

什麼原因造成的?

  • Github pages is loaded over https and your API request is over http, which is not allowed. You are serving the site over HTTPS but trying to load jQuery over HTTP. This is not allowed.

    除錯過程

  1. 檢查.gitinore是不是忽略到我的json檔
  2. 將路徑$.getJSON改成URL絕對路徑
    • $.getJSON('../data/content.json', function)
      把裡面的../data/content.json改成
    • https://hazelwu2.github.io/AjaxMasonryPhoto/data/content.json

重新更改路徑後,Gitpage就抓得到我的資料了。
初步判斷應該是因為HTTPS,但上傳到github是http,導致無法拿到資料。

如果有問題、筆誤或寫錯,歡迎糾正我,謝謝

參考網站