Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “错误”;与服务器的连接不成功。”;在Cordova和jQuery中_Android_Jquery_Cordova_Jquery Mobile - Fatal编程技术网

Android “错误”;与服务器的连接不成功。”;在Cordova和jQuery中

Android “错误”;与服务器的连接不成功。”;在Cordova和jQuery中,android,jquery,cordova,jquery-mobile,Android,Jquery,Cordova,Jquery Mobile,我使用Cordova和JQuery mobile为android创建了一个应用程序。当我使用google chrome测试运行代码时,它运行良好,但当我尝试在android emulator上使用android studio在cmd(locate>cordova Simulate android)运行它时,它不起作用 当我尝试在模拟器上运行它时,我得到: “与服务器的连接不成功(file:///android_asset/www/index.html)" 但是如果我不使用JQuery,它就可以正

我使用Cordova和JQuery mobile为android创建了一个应用程序。当我使用google chrome测试运行代码时,它运行良好,但当我尝试在android emulator上使用android studio在
cmd
locate>cordova Simulate android
)运行它时,它不起作用

当我尝试在模拟器上运行它时,我得到:

“与服务器的连接不成功(file:///android_asset/www/index.html)"

但是如果我不使用JQuery,它就可以正常工作。我没有修改JQuery或JQuery mobile中的任何代码

    <head>
        <-- import jquery and codovar -->
        <link rel="stylesheet" href="./css/jquery.mobile-1.4.5.min.css" />

        <-- if i remove this 3 line of code below program is working as same as open with google chrome -->
        <link rel="stylesheet" href="./css/jquery.mobile-1.4.5.min.css" />
        <script src="./js/jquery-2.1.4.min.js"></script>
        <script src="./js/jquery.mobile-1.4.5.min.js"></script>
        <--end remove here -->

        <script type="text/javascript" src="./js/Login.js"></script>

    </head> 
    <body>
        <div data-role="page" id="page1">
            <div data-role ="header" style="background-color: #00CCA5;">
                <h1 style="color: #FAF0BA; text-shadow: None; text-align: center;">LogIn</h1>
            </div>
            <div data-role ="main" class="ui-content"  >
                <div align="center">
                    <label>id:</label>
                    <input type="text" id="login_id">
                    <br>
                    <label>password:</label>
                    <input type="password" id="login_password">
                    <div id="wrong" style="color: red;"><br></div>
                </div>
                <button style="background-color: #FAF0BA; color:#00CCA5;" data-role ="button" data-icon ="forward" id="let_login">Log in</button>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
    </body>
</html>
这里是
MainActivity.java
(在读了一些旧文章后修改了文件,但仍然不起作用)

公共类MainActivity扩展了CordovaActivity
{
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//修改下面的行
super.setIntegerProperty(“loadUrlTimeoutValue”,70000);
//结束修改行
//在config.xml中设置
loadUrl(launchUrl);
}
}

注:这是我第一次使用Cordova和JQuery

当网页无法加载/无法访问时会发生此错误

要解决此问题,请创建一个新的html文件

main.html

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

窃窃私语
window.location='./index.html';
并将启动URL保持为config.xml中的main.html

// Set by <content src="main.html" /> in config.xml


    loadUrl(launchUrl);
//在config.xml中设置
loadUrl(launchUrl);

这将修复

我建议首先,要检查config.xml,可以在其中指定应用程序的起始页。它一定是指向“index.html”,我认为您的页面名为“Login.html”(只是猜测) 这个部分看起来像这样


我使用了以下方法:

<content src="./index.html" />


只需在页面地址之前添加
/
,它就可以工作了

我只将cordova和插件注入main.html,而没有注入index.html
// Set by <content src="main.html" /> in config.xml


    loadUrl(launchUrl);
<content src="./index.html" />