R
R
Rikonardo2019-09-18 00:23:42
Android
Rikonardo, 2019-09-18 00:23:42

Why can't the cordova application see the local server with ajax?

There is some homemade smart home device for which I am making an application on cordova.
The essence of the application is simple - to control the device by sending requests to its http server.
At startup, the application goes through all ip addresses from 192.168.0.0 to 192.168.0.255, sending asynchronous requests to them and achieving a response characteristic of our device.
The bottom line is that when you open the html-file of the application on a laptop, everything works as it should, but the finished application on Android 9 encounters the "Not found" error. From this I can conclude that it's not about JS and not about CORS headers, but about cordova settings.
Here is the config file. (I know that he already looks like a dump. These are traces of unsuccessful attempts to get him to see the server.)

config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.rikonardo.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>app</name>
    <description>
        Just the app!
    </description>
    <author email="[email protected]" href="http://example.com">
        Rikonardo
    </author>
    <preference name='phonegap-version' value='cli-5.2.0' />
    <preference name="android-build-tool" value="ant" />
    <content src="index.html" />
    <icon src="icon.png" />
    <feature name="http://api.phonegap.com/1.0/network"/>
  <preference name="android-minSdkVersion" value="1900" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <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:*" />
        <preference name="android-minSdkVersion" value="14" />
        <preference name="android-targetSdkVersion" value="26" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rikonardo, 2019-09-18
@REKTOR_RG

Issue resolved.
The solution was to install the cordova-plugin-whitelist plugin.
cordova plugin add cordova-plugin-whitelist

X
xmoonlight, 2019-09-18
@xmoonlight

1. https://stackoverflow.com/a/54639609
2. https://developer.android.com/training/articles/se...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question