Кордова Android не отправляет AJAX запрос - PullRequest
0 голосов
/ 10 июля 2020

Привет, я разработал приложение с использованием Cordova и в основном разработал его, сначала протестировав IOS. Я опубликовал приложение в App Store и теперь хочу опубликовать sh его в магазине Google Play.

Я тестировал приложение через android studio и не могу пройти через свой логин страница. Когда я заполняю форму и отправляю ее, не отправляется запрос AJAX на проверку моих учетных данных и вход в систему.

Я использую профилировщик студии android, чтобы проверить, сделан ли запрос, и могу не вижу ни одного. Я добавил ведение журнала перед запросом Ajax, но после того, как форма была отправлена ​​и она заработала.

После просмотра нескольких форумов я все еще не могу заставить его работать. Я добавил плагин белого списка, я правильно настроил CORS, потому что мне пришлось это сделать, чтобы он работал для IOS.

Вот моя конфигурация. xml file

<?xml version='1.0' encoding='utf-8'?>
<widget id="id" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Title</name>
    <description>
        description
    </description>
    <author email="email" href="http://cordova.io">
        Team
    </author>
    <content src="index.html" />
    <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:*" />
    <allow-navigation href="*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <preference name="WKWebViewOnly" value="true" />
        <config-file parent="NSLocationAlwaysAndWhenInUseUsageDescription" target="*-Info.plist">
            <string>Background location tracking is required to notify you when you enter a location offering deals</string>
        </config-file>
        <config-file parent="NSLocationAlwaysUsageDescription" target="*-Info.plist">
            <string>Background location tracking is required to notify you when you enter a location offering deals</string>
        </config-file>
        <config-file parent="NSLocationWhenInUseUsageDescription" target="*-Info.plist">
            <string>Background location tracking is required to notify you when you enter a location offering deals</string>
        </config-file>
        <config-file parent="NSMotionUsageDescription" target="*-Info.plist">
            <string>Device motion updates help determine when the device is stationary so the app can save power by turning off location-updates</string>
        </config-file>
    </platform>
    <preference name="StatusBarOverlaysWebView" value="false" />
    <preference name="StatusBarBackgroundColor" value="#262262" />
    <preference name="StatusBarStyle" value="lightcontent" />
    <preference name="orientation" value="portrait" />
    <preference name="DisallowOverscroll" value="true" />
    <plugin name="cordova-plugin-console" spec="~1.1.0" />
    <plugin name="cordova-plugin-statusbar" spec="^2.4.3" />
    <plugin name="cordova-plugin-dialogs" spec="^2.0.2" />
    <plugin name="cordova-plugin-wkwebview-engine" spec="~1.2.1" />
    <plugin name="cordova-plugin-wkwebview-file-xhr" spec="~2.1.4" />
    <plugin name="cordova-plugin-geofence" spec="^0.7.0" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <plugin name="cordova-background-geolocation-lt" spec="^3.7.0">
        <variable name="BACKGROUND_MODE_LOCATION" value="&lt;string&gt;location&lt;/string&gt;" />
    </plugin>
    <plugin name="cordova-plugin-cocoalumberjack" spec="~0.0.4" />
    <plugin name="cordova-plugin-qrscanner" spec="~3.0.1" />
    <plugin name="cordova-plugin-geolocation" spec="~4.0.2" />
    <plugin name="cordova-plugin-local-notification" spec="~0.9.0-beta.2" />
</widget>

Вот код AJAX, который, похоже, не делает никаких запросов.

$("#login_form").submit(function(e) {
    e.preventDefault()

    var form = $(this);
    var url = form.attr('action');

    $.ajax({
        type: "POST",
        url: 'login-url',
        data: form.serialize(), // serializes the form's elements.
        success: function(data) {
            storage.setItem('access_token', data.access_token) // Pass a key name and its value to add or update that key.
            window.location.href = "deals.html";
        },
        error: function(httpObj, textStatus) {
            if (httpObj.status == 401) {
                navigator.notification.alert(
                    'Please try again using the correct credentials.',
                    alertDismissed,
                    'Incorrect Details',
                    'Try Again'
                );
            }
        }
    });
});

Любая помощь будет очень признательна, спасибо.

1 Ответ

1 голос
/ 10 июля 2020

В config. xml, в разделе <platform name="android"> добавьте эти теги

<config-file target="app/src/main/AndroidManifest.xml" parent="/manifest">             
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />           
</config-file> 

, затем создайте или запустите для android снова и проверьте, можете ли вы получить доступ к Inte rnet

...