Ajax Cached Call

I have a problem in the application that I am creating. And I read a lot of threads about a similar problem and applied the suggestion given in these threads. However, the problem persists, so I am writing this.

The configuration is as follows:

  • I have 3 php file: index.php, step_one.phpand calculation.php.
  • From index.phpI successfully load step_one.phpthrough an Ajax call that looks like this:

    $(document).ready(function () {
            var nocache = Math.random() * new Date().getTime() + Math.random();
                $("#bookings").click(function () {
                    $.ajax({
                        url: 'step_one.php?cach='+nocache,
                        type: 'post',
                        cache: false,
                        success: function (data) {
                            $("#contentLeft").html(data);
                        }
                    });
                });
            });
    

Note: step_one.phpis a html form. Then in step_one.phpI enter the data into the form and submit the form data calculation.phpthrough another Ajax call, which looks like this:

$("#viewprice").click(function () {
    var nocache = Math.random() * new Date().getTime() + Math.random();
    $.ajax({
        url: 'calculate_quote.php?cache=' + nocache,
        type: 'post',
        dataType: 'json',
        cache: false,
        data: $("#stepOneForm").serialize(),
        success: function (data) {
            console.log(data);
            $(".quote").append(data);
            $(".quote").show();
            document.getElementById("price").value = data;
        }
    });
});

File calculation.php, calculates the price based on the data received and returns jsonto step_one.php. Here is how I return jsonfrom calculation.php:

header('Content-Type: application/json');
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Expires: 0'); // Proxies.
echo json_encode($data);

. #viewprice step_one.php. , step_one.php #viewprice, calculation.php. , , calculation.php, Ajax .

xamp. ? ?

+4
2

, . .

. . , ( ), , - , $data, to json_encode. , , .

, calculation.php , Ajax- . , . ; , , . , .

+1

AJAX POST-

, → >

0

Source: https://habr.com/ru/post/1609269/


All Articles