Cordova ajax调用在phonegap构建(cli 9)和android SdkVersion 28上不起作用

Cordova ajax调用在phonegap构建(cli 9)和android SdkVersion 28上不起作用,cordova,phonegap-build,hybrid-mobile-app,phonegap,Cordova,Phonegap Build,Hybrid Mobile App,Phonegap,我的android应用程序是用混合技术方法(HTML5、css、javascript)开发的,起初我用PhoneGapCLI8构建它,一切正常,工作正常。但是,当谷歌不再允许cli 8时,我最近用cli 9和sdk版本28重新构建了我的应用程序,但我面临的问题是,我不知道到底发生了什么。 我所有的ajax调用都不能对http服务器工作,但我可以调用对https服务器的ajax调用,例如,我可以调用对youtube API的ajax请求 这是我的config.xaml文件内容 <?x

我的android应用程序是用混合技术方法(HTML5、css、javascript)开发的,起初我用PhoneGapCLI8构建它,一切正常,工作正常。但是,当谷歌不再允许cli 8时,我最近用cli 9和sdk版本28重新构建了我的应用程序,但我面临的问题是,我不知道到底发生了什么。 我所有的ajax调用都不能对http服务器工作,但我可以调用对https服务器的ajax调用,例如,我可以调用对youtube API的ajax请求

这是我的config.xaml文件内容

    <?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.myDomain" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
   <name>AppName</name>
    <description>
        Application
    </description>
    <author email="info@myDomain.com" href="http://example.com ">
       author info
    </author>
    <content src="index.html" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="28" />
    <preference name="phonegap-version" value="cli-9.0.0" />
    <plugin name="cordova-plugin-battery-status" source="npm" spec="~1.1.1" />
    <plugin name="cordova-plugin-camera" source="npm" spec="~2.1.1" />
    <plugin name="cordova-plugin-media-capture" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-console" source="npm" spec="~1.0.2" />
    <plugin name="cordova-plugin-contacts" source="npm" spec="~2.0.1" />
    <plugin name="cordova-plugin-device" source="npm" spec="~1.1.1" />
    <plugin name="cordova-plugin-device-motion" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-device-orientation" source="npm" spec="~1.0.2" />
    <plugin name="cordova-plugin-dialogs" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-file" source="npm" spec="~4.1.1" />
    <plugin name="cordova-plugin-file-transfer" source="npm" spec="~1.5.0" />
    <plugin name="cordova-plugin-geolocation" source="npm" spec="~2.1.0" />
    <plugin name="cordova-plugin-globalization" source="npm" spec="~1.0.3" />
    <plugin name="cordova-plugin-inappbrowser" source="npm" spec="~1.3.0" />
    <plugin name="cordova-plugin-media" source="npm" spec="~2.2.0" />
    <plugin name="cordova-plugin-network-information" source="npm" spec="~1.2.0" />
    <plugin name="cordova-plugin-splashscreen" source="npm" spec="~3.2.1" />
    <plugin name="cordova-plugin-statusbar" source="npm" spec="~2.1.2" />
    <plugin name="cordova-plugin-vibration" source="npm" spec="~2.1.0" />
    <plugin name="cordova-plugin-whitelist" source="npm" spec="~1.3.4" />
    <platform name="android">
       <preference name="SplashScreenDelay" value="8000" />
        <icon density="ldpi" src="www/res/icon/android/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="www/res/icon/android/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="www/res/icon/android/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="www/res/icon/android/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="www/res/icon/android/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="www/res/icon/android/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="www/res/screen/android/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="www/res/screen/android/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="www/res/screen/android/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="www/res/screen/android/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="www/res/screen/android/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="www/res/screen/android/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="www/res/screen/android/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="www/res/screen/android/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="www/res/screen/android/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="www/res/screen/android/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="www/res/screen/android/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="www/res/screen/android/drawable-port-xxxhdpi-screen.png" />
    </platform>
    <splash src="splash.png" />
    <access origin="*" />
    <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>

    </widget>
它运行良好,可以从youtube获得受人尊敬的数据

但是当我调用ajax到我的(http)网站时,如下所示

$.ajax({
        url: 'http://www.example.com /JSONAPI.php',  //suppose example.com is my domain 
        method: 'get',
        dataType:"JSON",
        data: {'f': APIRouteName,'NumberOfRecords': NumberOfRecords, 'NumberOfOffset': NumberOfOffset},
        beforeSend: function () {
            displayloadOn();
            checkAjaxStatus=false;
        }, success: function (datas) {

         console.log(datas);
        }
    })
它在cordova cli 9和sdk版本28中总是失败,而在cli 8中则没有问题


拜托,我不知道怎么了?它在本地环境下运行良好,但在使用phonegap构建并将其运行到sumsung s8+手机后,对我的网站的所有ajax调用都不起作用,但只有我可以调用youtube api

您应该使用https连接来调用ajax 我也面临同样的问题,但经过一些研究,我发现, 根据API级别28,应用程序应使用https连接


所以在ajax调用中,您应该使用https,因为您的后台服务器使用的是不安全的http。这正是我想要的谢谢
  $.ajax({
                cache: false,
                url: 'https://www.googleapis.com/youtube/v3/playlists',
                type: "GET",
                contentType: "application/JSONP; charset=utf-8",
                dataType: "JSONP",
                crossDomain: true,
                data: {'part': 'snippet,contentDetails','channelId': 'youtubeChannelID', 'key': 'myAppKey'},
                beforeSend: function () {
                    displayloadOn();
                }, success: function (datas) {
                    displayloadOff();
                   console.log(datas);
                }
            })

        }
    });
$.ajax({
        url: 'http://www.example.com /JSONAPI.php',  //suppose example.com is my domain 
        method: 'get',
        dataType:"JSON",
        data: {'f': APIRouteName,'NumberOfRecords': NumberOfRecords, 'NumberOfOffset': NumberOfOffset},
        beforeSend: function () {
            displayloadOn();
            checkAjaxStatus=false;
        }, success: function (datas) {

         console.log(datas);
        }
    })