Cordova Connection to server was Unsuccessful

瘦欲@ 提交于 2019-12-10 12:59:53

问题


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

is showing when i run my android application. please let me know how to resolve this issue.


回答1:


For latest Cordova (4+) this a setting in config.xml:

e.g.

<preference name="LoadUrlTimeoutValue" value="70000"/>

Increases default timeout to 70 seconds (default is 20), reducing the chance of timing out.

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

When loading a page, the amount of time to wait before throwing a timeout error.




回答2:


This may asked here many times.. This issue can fix by adding a timeout to the webview call (index.html). In your project_name.java class just add this

 super.setIntegerProperty("loadUrlTimeoutValue", 5000);

And in Cordova latest, just use this to timeout

 super.loadUrl(Config.getStartUrl(), 5000);

Also go through these so questions

Question1

Question2

UPDATE :

One more solution, try this

Create a main.html and put your code there, and in your index.html just redirect to main.html

<script>
 window.location='./main.html';
</script>



回答3:


This blog post from Robert Kehoe:

  • Seemed to be EASY to me
  • Made sense to me
  • WORKED for me

Rename your index.html to "main.html"

Create a new "index.html" and put the following content into it:

<!doctype html>
<html>
  <head>
   <title>the title</title>
   <script>
     window.location='./main.html';
   </script>
  <body>
  </body>
</html>

Rebuild your app! No more errors!

Robert also said,

Another good idea is to give your application a “splash screen”, so that the user gets instant feedback that your app is loading/working, before it is fully ready.




回答4:


The main problem for this issue is take more time to load your page.

yes it's can a hack to solve this issue, make a html page name index.html and your existing index page name to be change as a main.html or any other one give a redirection to this page like this

    <script>
       window.location='main.html';
    </script>

am sure it's work very much




回答5:


hey i think this error may come load multiple script in starting time so it will take more time.

so you set like this in your java...

super.loadUrl("file:///android_asset/www/index.html");
super.setIntegerProperty("loadUrlTimeoutValue", 600000);

reference1 reference2



来源:https://stackoverflow.com/questions/23514622/cordova-connection-to-server-was-unsuccessful

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!