Need to do caching. The logic is this, clicking on the link (caching data), then clicking on the button (moving to other content), and pressing back the browser button [here and you need to substitute the cache] so as not to make a separate request to the database.

    1 answer 1

    I suggest you try a small jQuery Jalc plugin that caches AJAX requests using localStorage. And there is no need to reinvent the wheel.

    $.ajax({ localCache: true, cacheTTL: 2, cacheKey: 'list_of_phones', isCacheValid: function () { return true; }, url: '/phones', success: function (data, textStatus, jqXHR) { // Закэшированный запрос будет в переменной data. // Если в кэше нет данных или если они устарели, // то будет сделан AJAX-запрос, а его результат (если он // был успешным) также будет храниться в переменной data. }, error: function (jqXHR, textStatus, errorThrown) {/* ... */}, }); 
    • thanks, yes he came across to me. there is still a nuance to display data from different ajax requests (that is, these 3 requests provide a single page.) - Zimzibar
    • @Zimzibar, you can specify for each AJAX request a different key under which it will be stored in localStorage. See the cacheKey parameter. - neluzhin
    • Yes, I did it, but how can we print what is in localStorage? I do this: $ ('body'). (LocalStorage.getItem (main_page)) but I know there is just a .get method in Jalc, and it doesn't work. And another minus of Jalca is that my JSON comes in the form of for_json [0] and I parse it in ajax parseJSON [for_json [0]] What is not suitable for Jalc a bit and there is just null - Zimzibar
    • @Zimzibar, make a regular AJAX request. If the data is cached, the request will not be made, and the data will automatically be taken from localStorage. Added an example to your answer. - neluzhin
    • Thank you very much for your support, so look at me at the moment. 1) ajax request takes data from the main page, then 2 and 3 ajax requests take data and insert it into the 'body' of the main page. And why do I make a cache like this -> if they press a button and it moves to another page completely and then click back (that is, return to the main page) then I want to use the cache and simply take and print from the localstorage again to the body - Zimzibar