khu*_*ice 4 jquery android jquery-mobile cordova
我使用Cordova和JQuery mobile为Android创建了一个应用程序.当我使用谷歌浏览器测试运行代码时,它运行良好,但当我尝试在Android模拟器上使用android studio在cmd(locate>cordova emulate 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>
Run Code Online (Sandbox Code Playgroud)
这是 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");
}
});
});
Run Code Online (Sandbox Code Playgroud)
这里是MainActivity.java(阅读一些旧帖后修改过的文件,但仍然不起作用)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
PS.这是我第一次使用Cordova和JQuery
当网页无法加载/无法访问时,会发生此错误.
要解决此问题,请创建一个新的html文件
main.html中
<!doctype html>
<html>
<head>
<title>tittle</title>
<script>
window.location='./index.html';
</script>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
并将启动URL保留为config.xml中的main.html
// Set by <content src="main.html" /> in config.xml
loadUrl(launchUrl);
Run Code Online (Sandbox Code Playgroud)
这将解决
| 归档时间: |
|
| 查看次数: |
15432 次 |
| 最近记录: |