frequent AJAX requests cause page responses to slow down. then consider storing the data in window.storage so that only one Ajax request is required, not frequent requests.
Since only strings can be stored in localstorage, we need to use the json.stringify () and Json.parse ();
$.ajax ({
type: "Get",
async: "True",
URL: "",
data: {},
DataType: "Jsonp",
success:function (data) {
if (data instanceof array) {
Stroage.push (json.stringify (data[i));//storage is an externally-defined array storage = []
}
},
error:function () {
}
});
Now we store data in storage, when we need to use:
Fucntion GetData () {
window.localStorage.job = json.stringify (storage);//convert Storage to string store
var job = Json.parse (window.localStorage.job);
for (var i = 0; i < job.length i++) {
Job[i] = Json.parse (job[i));
In this case, the job is storing an array of objects
}
Local storage, in addition to Localstorage, there are sessionstorage.
(1) Localstorage and Sessionstorage are objects that are used to store temporary information for the client.
(2) Localstorage and Sessionstorage can only store objects of string type
(3) The Localstorage lifecycle is permanent unless the user manually clears the Localstorage information, otherwise this information will always exist.
(4) The Sessionstorage life cycle is the current window or tab, and once the window or tab is permanently closed, the data stored through the sessionstorage is emptied.
(5) Different browsers cannot share information in Localstorage or Sessionstorage. The same localstorage can be shared between different pages in the same browser (pages belong to the same domain name and port), but sessionstorage information cannot be shared between different pages or tabs.
The above is a small set to introduce the Localstorage in the storage object array and read the method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!