简体   繁体   English

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

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

I am using latest version of Cordova (v10.x) and Cordova Android (v10.x).我使用的是最新版本的 Cordova (v10.x) 和 Cordova Android (v10.x)。 Also I am using Framework7 for html/template.我也使用 Framework7 的 html/模板。

The Ajax "POST" and "GET" is working fine on browser $ cordova run browser Ajax“POST”和“GET”在浏览器上运行良好$ cordova run browser

But on Android "GET" method is working fine but "POST" method is not working.但在 Android 上,“GET”方法工作正常,但“POST”方法无效。 Sample Ajax type "GET" -样品 Ajax 输入“GET” -

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

But if it is type: 'POST' then it doesn't work, I mean it doesn't run, it doesn't try access the API url. I have tried many solutions/solved answers available on stackoverflow for similar cases but none of them works (actually those answers are for old versions)但如果它是type: 'POST'那么它不起作用,我的意思是它不运行,它不会尝试访问 API url。我已经尝试了很多解决方案/已解决的答案,可在 stackoverflow 上找到类似的案例,但没有其中的作品(实际上这些答案是针对旧版本的)

In my config.xml file, I have this:在我的config.xml文件中,我有这个:

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

And in my AndroidManifes.xml -在我的 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>

Almost 3 years ago I build a similar app and it works well.大约 3 年前,我构建了一个类似的应用程序并且运行良好。 At that time there was an Cordova plugin "Whitelist".当时有一个Cordova插件“白名单”。 But with this new version cordova Whitelist plugin is not supported.但是这个新版本 cordova 不支持白名单插件。 Even if I add it manually, it get skipped automatically.即使我手动添加它,它也会自动跳过。

Please suggest.请建议。 I am exhausted:-(我累死:-(

  1. Uninstall whitelist plugin卸载白名单插件
  2. Remove android platform, then add this code to your config.xml :删除 android 平台,然后将此代码添加到您的config.xml
<access origin="*" />
.
.
.
<preference name="AndroidInsecureFileModeEnabled" value="true" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有人成功地将您的 ionic cordova Hybrid 应用程序从 android 9.x 版升级到 android Cordova 10.x 版 - Has anybody successfully upgraded your ionic cordova Hybrid app from android version 9.x to android Cordova version 10.x 当 ionic cordova 在 Mac 10.x 上构建 android 时,gradle 失败 - gradle fails when ionic cordova build android on Mac 10.x Delphi 10.3.3, Android App AutoStart on Boot (Android 8.x, 10.x) - Delphi 10.3.3 , Android App AutoStart on Boot ( Android 8.x , 10.x ) 科尔多瓦平台添加Android无法正常工作 - cordova platform add android not working 如何在 Delphi 10.X 或 Delphi 11.X 中安装额外的 Android SDK? - How to install additional Android SDK into Delphi 10.X or Delphi 11.X? 具有特定版本的“cordova 添加平台 android” - 'cordova add platform android' with specific version Cordova 10 无法将 ajax 发布到 http Z572D4E421E5E6B9BC111D815E8Z07 - Cordova 10 unable to post ajax to http url 对将第 3 方 android aar 库导入 Delphi 10.x 项目有疑问 - Have a question about importing 3rd party android aar library into Delphi 10.x project 升级Cordova导致Android平台停止工作 - Upgrading Cordova caused Android Platform to stop working 全球化在适用于Android平台的Cordova 4.3.0中不起作用 - Globalization not working in cordova 4.3.0 for android platform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM