簡體   English   中英

Cordova(版本 10.x)- Ajax POST 方法不適用於 Android 平台

[英]Cordova (version 10.x) - Ajax POST method not working for Android platform

我使用的是最新版本的 Cordova (v10.x) 和 Cordova Android (v10.x)。 我也使用 Framework7 的 html/模板。

Ajax“POST”和“GET”在瀏覽器上運行良好$ cordova run browser

但在 Android 上,“GET”方法工作正常,但“POST”方法無效。 樣品 Ajax 輸入“GET” -

$.ajax({
        type: 'GET',
        data: {
            "privacy": "yes"
        },
        url: 'https://api_link_here.com',
        success: function(response) {
            //THIS WORKS FINE
        }
});

但如果它是type: 'POST'那么它不起作用,我的意思是它不運行,它不會嘗試訪問 API url。我已經嘗試了很多解決方案/已解決的答案,可在 stackoverflow 上找到類似的案例,但沒有其中的作品(實際上這些答案是針對舊版本的)

在我的config.xml文件中,我有這個:

<content src="index.html" />
<access origin="*" />
<allow-navigation href="*" />
<preferance name="android-usesCleartextTraffic" value="true" />
.....

在我的 AndroidManifes.xml -

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.mywebsite.app" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

大約 3 年前,我構建了一個類似的應用程序並且運行良好。 當時有一個Cordova插件“白名單”。 但是這個新版本 cordova 不支持白名單插件。 即使我手動添加它,它也會自動跳過。

請建議。 我累死:-(

  1. 卸載白名單插件
  2. 刪除 android 平台,然后將此代碼添加到您的config.xml
<access origin="*" />
.
.
.
<preference name="AndroidInsecureFileModeEnabled" value="true" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM