2016-04-27 61 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)说明 –