I am trying to do display pages built client-side (HTML/Javascript) using JSON data.
- 4 pages, built using the same JSON object So I don't want to retrieve the JSON each time I generate the page.
That is why I created this function:
function retrieve_user_info() {
////////
// Here, code that decides whether we use the local data or if we call the server again
////////
var request_in = {
UserId:1
};
$.ajax({
url: "http://localhost:2000/getInfo",
async: false,
cache: false,
data: request_in,
dataType: 'json',
timeout: 4000,
success: function(data) {
console.log('success')
returnValue = data;
}
});
sessionStorage.user = returnValue;
}
In each page, I do the following: - call function retrieve_user_info(), to update (or not) the local copy - generate the page using the local copy
So this works locally using "async: false", but in cross-domain it fails, as written in the documentation. My question is how to handle this. - I do not want to duplicate the server call to each page. - I do want to avoid retrieving the data too often
Thanks in advance, S.
Edit: After what I can read, it seems that it is simply not possible. I don't think this is a duplicate, because I don't want to tie the function that retrieves info from server with the function that generates the page. But apparently I have to. Thank you for your answers.
Comments: Strange that there is no easy way to cache data locally