2017-09-03 64 views
0

我一直在努力使對我的node.js服務器的AJAX調用沒有成功。使用科爾多瓦的Android中的AJAX失敗

我也做了以下內容:

1)安裝了CORS包在我的node.js服務器。 AJAX確實在瀏覽器中工作。

2)增加了以下內容安全策略的index.html:

<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://maps.googleapis.com https://163.172.175.135"> 

3)添加了幾行我的config.xml:

<?xml version='1.0' encoding='utf-8'?> 
<widget id="roda.X.XXXX" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
    <name>Roda</name> 
    <description> 
     A sample Apache Cordova application that responds to the deviceready event. 
    </description> 
    <author email="[email protected]" href="http://cordova.io"> 
     Apache Cordova Team 
    </author> 
    <content src="index.html" /> 
    <access origin="*" /> 
    <allow-navigation href="*" /> 
    <allow-intent href="*" /> 
    <allow-intent href="http://*/*" /> 
    <allow-intent href="https://*/*" /> 
    <allow-intent href="tel:*" /> 
    <allow-intent href="sms:*" /> 
    <allow-intent href="mailto:*" /> 
    <allow-intent href="geo:*" /> 
    <platform name="android"> 
     <allow-intent href="market:*" /> 
    </platform> 
    <platform name="ios"> 
     <allow-intent href="itms:*" /> 
     <allow-intent href="itms-apps:*" /> 
    </platform> 
    <engine name="android" spec="^6.2.3" /> 
    <engine name="browser" spec="^4.1.0" /> 
    <plugin name="cordova-plugin-geolocation" spec="^2.4.3" /> 
    <plugin name="cordova-plugin-whitelist" spec="^1.3.2" /> 
</widget> 

有什麼我錯過了?

+0

請添加確切的錯誤信息 – Phonolog

+0

不知何故,只有當我將APK簽名並上傳到Google Play商店時纔會出現問題。如果我要通過電纜傳輸APK,並直接在我的手機中運行AJAX,則會起作用。 –

回答

0

我後來發現,AJAX可以在調試模式下工作,但不能在發佈模式下工作。問題是我使用的是IP地址而不是域名連接到服務器,從而導致SSL驗證失敗。在調試模式下,SSL證書未驗證。

Phew。問題解決了!

相關問題