您的位置:首页 > 移动开发

Application Error - The connection to the server was unsuccessful.

2017-03-30 17:21 323 查看
最近用phonegap封装前端页面做的项目时,遇到一个问题,分享一下,希望可以帮到有同样问题的朋友。
在启动应用时会报错:Application Error - The connection to the server was unsuccessful.
(file:///android_asset/www/index.html)
导致这个错误的原因是:
在安卓load页面时,页面需要加载的内容没有加载完。所以需要增加超时时间,或加一个过渡页来避免这个问题。
方案如下:
1.在load页面时,先load一个空的页面,当页面load完成时,再加载现在的index.html,步骤如下:
1)将你的"index.html"改名为"main.html";
2)创建一个新的"index.html",把下面的内容放到"index.html"中,
<script type="text/javascript">
window.location="./main.html";
</script>.
2.将LoadUrlTimeoutValue设置为50或60秒,默认是20秒(此方案只能减少这个错误,无法从源头解决问题),
在config.xml中增加下面这行:
<preference name="loadUrlTimeoutValue" value="50000" />

注:第二种方案只会减少产生这种错误,但不会从根本上避免这个问题,所以建议使用第一种方法,
第二种可以作为辅助手段。

如果是在中间弹出的这个错误框,可能是由以下原因导致的:
The problem is likely due to the speed of the emulator so the network is too slow complete the communication in a timely fashion.
This can be due to:
as you said you made some UI modifications, may be the size of images are high)
2.Your script may have a infinite or long loop, so that it takes too much of time to load.
3.You will be using too much of scripts (jQuery, iscroll, etc etc.. more number of plugins or scripts )
超时引起的问题可以增加超时时间,增加loadUrlTimeoutValue的值;
如果是由图片引起的,建议可以通过降低图片的色位,大小等。

想起之前架构师的一句话,分享给大家:代码是最不会骗人的,遇到的问题,就去查代码吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐