【发布时间】:2014-01-30 18:32:33
【问题描述】:
我的 phonegap 应用程序中有一个奇怪的行为,我似乎找不到解决方案。
我的应用有一个登录表单,成功登录后会重定向到更新帐户页面。
登录.HTML
setTimeout(function() {
$.mobile.changePage('update-account.html', { reloadPage: true, transition: "slide"} );
}, 2000);
在更新帐户表单中
更新帐户.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,它们确实可以工作。
这与我在重定向后如何加载页面有关吗?我是否无法以某种方式正确加载内容?这就像它需要重新加载页面才能正常运行。
【问题讨论】:
-
您在哪个文件中提供了 onclik 事件以及如何加载它们?
-
在同一页面中,我具有按钮在单击事件中调用的功能。我已经重新编辑了上面的代码
标签: jquery jquery-mobile cordova