The error "Connection to the server was unsuccessful." in Cordoba and jQuery

I created an Android app using Cordova and jQuery mobile. It works well when I test the code using google chrome, but when I try to run it on the Android emulator using the Android studio in cmd( locate>cordova emulate android), it does not work.

When I try to run it on an emulator, I get:

"The connection to the server was unsuccessful. (File: ///android_asset/www/index.html)"

But if I do not use jQuery, it works fine. I have not modified the code in jQuery or 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>

and here login.js

$(document).ready(function () {
    $("#let_login").on("tap",
            function () {
                var id = $("#login_id").val();
                var password = $("#login_password").val();
                if (id == "test" && password == "password") {
                    document.location.href = "./customer.html";
                    //$.mobile.changePage("./customer.html");
                }
                else {
                    $("#wrong").html("Wrong id and/or password");

                }
            });
});

and here MainActivity.java(modified file after reading the old message, but still not working)

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        //modify line below
        super.setIntegerProperty("loadUrlTimeoutValue", 70000);
        //end modify line 

        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }
}

ps. this is my first time using Cordoba and jQuery

+4
3

config.xml, . ponting to index.html, , "Login.html" ( ) :

<content src="your_page.html" />
Hide result

. , N, . , .

+1

, - /.

, html

main.html

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

URL- main.html config.xml

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


    loadUrl(launchUrl);

+7

:

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

./ , !

0

All Articles