V
V
Vadim2015-10-24 15:12:59
PHP
Vadim, 2015-10-24 15:12:59

How to organize the storage of intermediate data for multiple ajax calls?

Hello! Please help with advice on how best to store intermediate data. The meaning is that in the online store on the product selection page (in my case, fabric), when you click on the product thumbnail, an ajax request is sent to the server with parameters to select from the database:

$(document).ready(function() {
    $('#select-menu').find('a').click(function() {
        var itemData = $(this).attr('href');
        $.ajax({
            type: "POST",
            url: "cloth_data.php",
            data: itemData,
            cache: true,
            success:
                function processData(data) {
                    $(".ajax-loader").show().css("opacity", 1);
                    var img = $(data).find("figure").find("img").css("opacity", 0);
                    var clothImg = $(data).find(".clothImg").css("opacity", 0);
                    var title = $(data).find(".clothTitle");
                    var mnSelect = $(data).find(".mainSelect").attr('href');
                    var price = $(data).find(".itemPrice");
                    var debug = $(data).find(".debugItm");
                    img.on("load", function () {
                        setTimeout(function() {
                            $(".ajax-loader").css("opacity", 0);
                        }, 200);
                        setTimeout(function() {
                            $(".ajax-loader").hide();
                        }, 500);
                        $(this).css("opacity", 1);
                    });
                    clothImg.on("load", function () {
                        $(this).css("opacity", 1);
                    });
                    $("#item-wrapper").find(".main").replaceWith(img);
                    $(".price").show();
                    $(".clothImg").replaceWith(clothImg);
                    $(".itemPrice").replaceWith(price);
                    $(".clothTitle").replaceWith(title);
                    $(".selectBlock").show();
                    $(".mainSelect").attr('href', mnSelect);
                    $(".debugItm").replaceWith(debug);
                }
        });
        return false;
    });
});


But you need to choose 2 more types of fabric, in addition to the main one, in order to place an order. To do this, you need somewhere to store the data of the first POST request and, accordingly, the next one. I put this data in $_COOKIE in the handler, but the trouble is that it is necessary to display it to the user immediately, in the form of a response from the server, and this cannot be done without updating the handler page. Maybe someone knows a way to display data from $_COOKIE without refreshing the page? Or some other storage method? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Khomenko, 2015-10-24
@J01

In a backend session? In localStorage on the frontend?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question