0
我在我的phonegap應用程序中有一個奇怪的行爲,我似乎無法找到解決方案。mobile.changePage頁面不'active'後在phonegap JQM應用程序重定向
我的應用程序有一個登錄表單,在登錄成功後,重定向到更新帳戶頁面。
的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,他們的確會工作。
這是我在重定向後如何加載頁面?我無法正確加載內容嗎?這就像它需要一個頁面重新加載才能正常工作。
你給了onclik事件的文件以及你如何加載它們? –
在同一頁面中,我具有按鈕在click事件上調用的功能。我上面重新編輯了我的代碼 – user3189734