Cordova连接到服务器是不成功的

8 android cordova cordova-3 cordova-plugins

The Connection to the server was unsuccessful(file:///android-asset/www/index.html)

当我运行我的Android应用程序时显示.请告诉我如何解决此问题.

Dun*_*unc 23

对于最新的Cordova(4+)这个设置config.xml:

例如

<preference name="LoadUrlTimeoutValue" value="70000"/>
Run Code Online (Sandbox Code Playgroud)

将默认超时增加到70秒(默认值为20),从而减少超时的可能性.

文档:https://cordova.apache.org/docs/en/latest/config_ref/index.html#preference

加载页面时,抛出超时错误之前等待的时间.


man*_*ukv 8

这可能在这里问过很多次.这个问题可以通过在webview调用(index.html)中添加超时来解决.在你的project_name.java类中添加它

 super.setIntegerProperty("loadUrlTimeoutValue", 5000);
Run Code Online (Sandbox Code Playgroud)

在Cordova最新版本中,只需使用此功能即可暂停

 super.loadUrl(Config.getStartUrl(), 5000);
Run Code Online (Sandbox Code Playgroud)

还要经历这些问题

问题1

问题2

更新:

还有一个解决方案,试试吧

创建一个main.html并将代码放在那里,然后在index.html中重定向到main.html

<script>
 window.location='./main.html';
</script>
Run Code Online (Sandbox Code Playgroud)