$ .ajax Phonegap APK构建现在无法正常工作

时间:2018-10-26 10:54:58

标签: android ajax cordova post phonegap

我正在使用最新版本的PhoneGap,并且正在执行ajax调用。

function setting_main() {
        var smsid = localStorage.getItem('registrationId');
        var model = device.model;
        var uui = device.uuid;
        var platform = device.platform;

        var url_webservice = 'http://mywebsite.com/webservice/db.php';

        $.ajax({
            type: 'POST',
            url: url_webservice,
            data: 'act=check_device&model=' + model+'&uui='+uui+'&platform='+platform+'&smsid='+smsid,
            dataType: 'json',
            success: function (res) {
                localStorage.setItem("unit", res.unit);
                localStorage.setItem("id_device", res.id);
                localStorage.setItem("login_before", res.login_before);
                localStorage.setItem("user_id", res.user_id);
                localStorage.setItem("user_key", res.user_id);
                localStorage.setItem("user_type", res.user_type);
                localStorage.setItem("user_key_parent", res.user_key_parent);
                if(res.login_before==0){
                    window.location.replace('login.html');
                }else{
                    if(res.user_type!=1) {
                        window.location.replace('groups.html');
                    }else{
                        window.location.replace('groups_teacher.html');
                    }
                }
            }
        });
    }
    document.addEventListener('deviceready', setting_main, false);

之前,此代码有效,但是在本周,当我在桌面浏览器或移动PhoneGap Developer应用程序上测试我的应用程序时,它可以正常工作,但是在构建应用程序(.apk)之后,ajax请求无法正常工作,并且会因失败而失败比成功更重要。我已经完成了提到的所有配置,其中包括:

<preference name="DisallowOverscroll" value="false" />
<preference name="android-minSdkVersion" value="17" />
<preference name="android-targetSdkVersion" value="26" />
<preference name="orientation" value="portrait" />
<plugin name="cordova-plugin-battery-status" spec="~1.2.2" />
<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="phonegap-plugin-barcodescanner" source="npm" spec="~6.0.0"/>
<plugin name="cordova-plugin-console" source="npm" spec="~1.0.2" />
<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-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-whitelist" spec="~1.3.1" />

<plugin name="cordova-plugin-vibration" spec="~2.1.3" />
<plugin name="phonegap-plugin-push" source="npm" spec="~1.8.0">
    <variable name="SENDER_ID" value="407902603339" />
</plugin>

<plugin name="cordova-android-support-gradle-release" source="npm" spec="~1.4.5"/>

    <access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />

<platform name="android">
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="*" />

</platform>
<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
</platform>

还在我的HTML中添加了Content-Security-Policy元标记,并指向我的API所在的域:

<meta http-equiv="Content-Security-Policy"
      content="default-src *;
               style-src 'self' 'unsafe-inline' 'unsafe-eval';
               script-src 'self' 'unsafe-inline' 'unsafe-eval';">

我正在使用build.phonegap.com在线构建服务来构建应用程序。请我真的需要帮助,因为我已经完成了所有可以找到但尚未成功的修复程序。

0 个答案:

没有答案
相关问题