admin管理员组

文章数量:1410717

I have in simulation.jsp the following code, by which I receive some simulation data from struts2 action:

$(document).ready(function() {
var data='<s:property escape="false" value="simInfos" />';
}

Now I do some simulation with this data. After the simulation has been done, how can I reload/refresh this page with button-click without losing this data, which I have received from struts2 action?

I have in simulation.jsp the following code, by which I receive some simulation data from struts2 action:

$(document).ready(function() {
var data='<s:property escape="false" value="simInfos" />';
}

Now I do some simulation with this data. After the simulation has been done, how can I reload/refresh this page with button-click without losing this data, which I have received from struts2 action?

Share Improve this question asked Apr 13, 2012 at 5:09 Max_SalahMax_Salah 2,50711 gold badges42 silver badges69 bronze badges 2
  • If it's a lot of data you need to use ajax to store and retrieve it from the server. – Erik Reppen Commented Apr 13, 2012 at 5:25
  • use hiddenfield control to store variable value. – Rony SP Commented Apr 13, 2012 at 6:22
Add a ment  | 

2 Answers 2

Reset to default 4
$(document).ready(function() {
    var data='<s:property escape="false" value="simInfos" />';
    localStorage["myData"] = data;

    // later on (maybe after page refresh, whatever)
    var myLoadedData = localStorage["myData"];
}

You can treat HTML5's localStorage like any other object, although it has specific setter and getter functions and can only store strings. Don't treat it like a permanent cache though, just a place to store some data for a little while. Another reference.

You may want to use this Cross-browser local storage API: http://www.jstorage.info/

You can use it like how you use HTM5's localStorage ;D

$.jStorage.set("foo", "value");  //Set "value" in "foo"
var txt = $.jStorage.get("foo");  //"txt" is now "value"

本文标签: javascriptHow to reload the page without losing variables valueStack Overflow