我的手机应用程序中有一个奇怪的行为,我似乎无法找到解决方案。
我的应用程序有一个登录表单,成功登录后会重定向到更新帐户页面。
的login.html
setTimeout(function() {
$.mobile.changePage('update-account.html', { reloadPage: true, transition: "slide"} );
}, 2000);
在更新帐户表单中
UPDATE-ACCOUNT.HTML
<script type="text/javascript">
$(document).ready(function() {
$('#updateAcc').tap(function(){
var formData = $("#callUpdateForm").serialize();
$.ajax({
type: "POST",
url: "/process/update-account.php",
cache: false,
dataType: 'json', // JSON response
data: formData,
success: function(res) {
if (res.success) {
$("#notify .success").show(); //show success message
$("#notify .success").delay(2000).hide("slow");//fades it out
setTimeout(function() {
$.mobile.changePage('account.html', { reloadPage: true, transition: "fade"} ); //redirects to profile
}, 2000);
} else {
// show error message
$("#notify .error").show(); //show error message
$("#notify .error").delay(2000).hide("slow"); //fades it out
}
},
error: function() {
alert('not working');
}
});
return false;
});
});
</script>
<script type="text/javascript">
function getAccount() {
$.getJSON("/json/account.json.php", {id : localStorage.getItem("id")}, function(data){
$.each(data, function(key, val){
// for populatingform
$('#usernameField').attr('value', val.username);
$('#passwordField').attr('value', val.password);
});
});
$(document).ready(function() {
//form processing goes here and works ok
getAccount();
});
</script>
<form id="callAccForm" enctype='multipart/form-data'>
<input type="text" name="username" id="usernameField" value="" placeholder="Username"/>
<input type="password" name="newpassword" value="" placeholder="New Password"/>
<a href"#" button id="updateAcc" data-role="button">Save</a>
</form>
关键问题是,在从登录页面重定向之后,在数据正确填充的情况下,除了带有onclick事件的任何其他按钮之外,更新按钮也不起作用。但是,如果我直接点击update-account.html,它们确实有用。
这与重定向后如何加载页面有关吗?我是否未能以某种方式正确加载内容?这就像需要页面重新加载才能正常运行。
答案 0 :(得分:0)
你可以查看repo这将为你的app jqm + backbone提供一个webskeleton,动画中的所有问题和像你这样的问题都在那里得到解决。它也是jqm的最佳骨架,可以让你的应用在phonegap上轻量化