[英]How can I get value in my Javascript page after page refresh
<a href="<?php echo base_url(); ?>userprofile/userprofile/2" style="color:white; margin-top:2rem;" onclick="senduser(2);">User2</a>
點擊“User2”后,頁面刷新。 但是為了獲取圖像,我需要向我的 app.js 文件發送一個 Id 值。 我嘗試使用 onclik 功能提供此功能。 很遺憾! 頁面刷新后就不行了!
function senduser($id){
var limit_load = 5;
var start_load = 0;
var userId = $id;
function load_photo_profile(limit_load, start_load, userId) {
var url = baseUrl + "userprofile/loadmore";
$.post(url, { limit: limit_load, start: start_load, userId: userId }, function (response) {
$(".included_image").append(response);
$('#mygallery').justifiedGallery({
rowHeight: 285,
lastRow: 'nojustify',
margins: 10
});
});
};
load_photo_profile(limit_load, start_load, userId);
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
start_load = start_load + limit_load;
load_photo_profile(limit_load, start_load, userId);
}
});
}
這個 id 觸發完全地工作這個功能。 跟隨它觸發 ajax post 方法以在 mygallery 元素內呈現代碼。 另一方面,我必須刷新我的頁面。
您可以使用sessionStorage來保存您需要的值,因此在刷新頁面后,您可以訪問該值,您可以像這樣創建它:
sessionStorage.setItem('nameOfItem', "mysavedValue");
對於訪問sessionStorage
值:
sessionStorage.getItem('nameOfItem')
會話存儲是臨時的,只要當前窗口打開,數據就會在窗口關閉時丟失,而本地存儲是持久的,並且在會話之間保持完整,除非有人刪除它。
localStorage.setItem("nameOfItem","valueofitem");//set
localStorage.getItem("nameOfItem"); //get
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.