如何在phonegap android应用程序中重定向到本地html页面?
我正在尝试使用phonegap创建一个android应用程序,第一页是登录页面,它向服务器查询用户身份验证,服务器返回json字符串:如果登录成功则返回true,否则返回false。我收到响应,但无法重定向到下一个 html 页面。我正在使用以下代码
$('#loginForm').submit(function(){
var uid = $('#login').val();
var pwd = $('#password').val();
$.getJSON('http://example.com/phonegap/login.php',
{ userid: uid, password: pwd },
function(json) {
$.each(json, function(k, v) {
if(v == "true" || v == true){
super.loadUrl("file:///android_asset/www/page2.html");
} else {
$('#loginError').html("Login failed, username and/or password don't match");
}
});
});
return false;
});
请告诉我,成功登录后如何将用户重定向到 page2.html?
I am trying to create a android app with phonegap, the first page is the login page, it queries to a server for user authentication, the server returns json string: true if the login is successful or false otherwise. I am getting the response but i am not able to redirect to next html page. I am using the below code
$('#loginForm').submit(function(){
var uid = $('#login').val();
var pwd = $('#password').val();
$.getJSON('http://example.com/phonegap/login.php',
{ userid: uid, password: pwd },
function(json) {
$.each(json, function(k, v) {
if(v == "true" || v == true){
super.loadUrl("file:///android_asset/www/page2.html");
} else {
$('#loginError').html("Login failed, username and/or password don't match");
}
});
});
return false;
});
Please let me know, how can I redirect the user to page2.html after successful login?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用 window.location 调用其他 html 页面,并且如果 www 文件夹中存在的第二个 html 页面未提供完整路径(请删除您的本机路径)。
请查看以下代码。
You can call other html pages using window.location and if your second html page present in www folder dont give full path (Please remove your native way path).
Please check out following code.
从纯 JavaScript 的角度来看,
window.location.href = 'something.html';
不起作用吗?from a pure javascript perspective,
Will
window.location.href = 'something.html';
not work?尝试 jQuery 加载方法
http://api.jquery.com/load/
Try the jQuery load method
http://api.jquery.com/load/
karnyj 是对的,因为标记的解决方案在 iOS 上存在缺陷。使用 window.location = "url" 有时会冻结 iOS 中的应用程序(每次重新启动设备时都会发生)。
//这就是要走的路
window.location.href = 'something.html';
karnyj is right, as the marked solution is bugged for iOS. Using window.location = "url" will sometimes freeze the application in iOS (happens every time I restart the device).
//This is the way to go
window.location.href = 'something.html';
相对路径应该没问题。
我发现
window.location = './yourPage.html'
(并且window.location.href = './yourPage.html'
) 并不总是有效,并已成功使用:
window.location.replace('./yourPage.html');
Relative paths should be fine.
I have found
window.location = './yourPage.html'
(andwindow.location.href = './yourPage.html'
) don't always work,and have had success using :
window.location.replace('./yourPage.html');