2016-04-27 95 views
0

我添加的數據在阿賈克斯的頁面,然後我改變頁面 ​​ 但後來當我刷新瀏覽器我都添加了Ajax的內容是不存在了。jQuery Mobile的防止瀏覽器重裝

+0

你能提供Ajax調用/功能,您使用的? –

+0

$阿賈克斯({ 網址:postDetailsUrl, 類型: 「後」, 數據:{ID:ID}, 成功:功能(數據){ $( '#commentList')HTML(數據); 。 $('#commentsNum')。text($('#commentList .comment')。) } }); –

回答

0

刷新頁面將刪除阿賈克斯的數據,來解決你需要添加你的Ajax調用pageshow事件中像下面

$(document).on("pageshow","#postDetails",function(){ 
$.ajax({ 
    url: postDetailsUrl, 
    type: "post", 
    data: {id: id}, 
    beforeSend: function() { 
     $.mobile.loading("show"); 
    }, 
    complete: function() { 
     $.mobile.loading("hide"); 
    }, 
    success: function (data) { 
     $('#commentList').html(data); 
     $('#commentsNum').text($('#commentList .comment').length); 
     initCommentPage();    
    }, 
    error: function (requestObject, error, errorThrown) { 
     alert("Error in communication"); 
    } 
}); 
}) 

現在這個AJAX請求是pageshow事件,以便顯示每次popstDetails頁面問題它會對postDetailsUrl進行ajax調用並在commentList元素中顯示數據。

瞭解更多有關頁面事件看gajotres的blog

+0

謝謝Arpit,但我如何存儲身份證? –

+0

存儲在瀏覽器的本地存儲中。 設定值'localStorage.setItem( 'idkey',idValue);' ,並獲得值'idvalue = localStorage.getItem( 'idkey');' 點擊[更多](HTTP:// WWW .w3schools.com/html/html5_webstorage.asp)說明 –

相關問題