當我在Android模擬器或Android設備上運行我的應用程序時,出現以下所有AJAX請求錯誤:Apache Cordova:加載資源失敗:服務器響應的狀態爲404(未找到)
Failed to load resource: the server responded with a status of 404 (Not Found)
我嘗試了以下所有步驟來解決此問題,但它仍然存在。
- 使用npm將白名單插件安裝到項目中。
- 已添加
<plugin name="cordova-plugin-whitelist" version="1" />
至 config.xml。 - 向平臺\ android \ AndroidManifest.xml添加了
<uses-permission android:name="android.permission.INTERNET" />
。 - 增加
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline';">
和<meta http-equiv="X-XSS-Protection" content="0">
到www/index.html文件的<head>
。 - 將
<access origin="*" />
,<allow-navigation href="*" />
和<allow-intent href="*" />
添加到config.xml文件中。
無論我還是得到相同的錯誤。有任何想法嗎?
項目編譯得很好。我在Windows 7上,使用科爾多瓦5.4.0,安卓5.1.1
我很抱歉,但我不小心從刪除的通配符*我的Content-Security-Policy標籤,事實上包含了它,我編輯了我的問題。所以這並不能解決問題。我試過你的內容安全策略元來限制請求只有一個域名,我仍然得到: '404(Not Found)' 但是,對於內容安全策略實際上不允許的其他域現在,我得到: '拒絕加載腳本,因爲它違反了以下內容安全策略...' 因此,可能是404錯誤是由Content-Security-Policy以外的其他內容引起的。如何調查更多? – Kaspi
我會嘗試使用[Chrome遠程調試工具](https://developers.google.com/web/tools/chrome-devtools/debug/remote-debugging/remote-debugging?hl=en)並查找任何JavaScript控制檯錯誤,以及嘗試Ajax調用時網絡選項卡上發生的情況。這可能會讓問題更清楚。 –