IE browser caching and jQuery form plugin

Like so many lost souls in front of me, I'm floundering in a snake hole, which is submitting an Ajax form and caching the IE browser.

I am trying to write a simple script using the jQuery Form plugin for Ajaxify Wordpress comments. It works fine in Firefox, Chrome, Safari, etc. al., But in IE the response text is cached with a result that Ajax causes an incorrect comment.

    jQuery(this).ajaxSubmit({
        success: 
            function(data) {
                var response = $("<ol>"+data+"</ol>");
                response.find('.commentlist li:last').hide().appendTo(jQuery('.commentlist')).slideDown('slow');
            }           
        });

ajaxSubmit sends a comment to wp-comments-post.php, which explicitly spits out the entire page as an answer. Therefore, despite the fact that it is ugly, like toads, I stick to the text of the answer in a variable, using: the latter to isolate the last comment and sweep it in its place.

IE, however, returns a cached version of the page that does not include a new comment. Therefore, ".commentlist li: last" selects the previous comment, a duplicate of which then glides uselessly down below the original.

I tried to set "cache: false" in the ajaxSubmit options, but this does not affect. I tried setting the url parameter and binding it to a random number or timestamp, but it joins the POST, which sends a comment to the server, and not the GET, which returns a response, and therefore has no effect. I'm not sure what else to try. Everything works fine in IE if I turn off browser caching, but this is obviously not what I can expect when anyone views a page.

Any help would be greatly appreciated. Thanks in advance!

. PHP , . , wp-comments-post , , , - post Wordpress, - , .

php - "if is_ajax" - - pageloads, , Ajax GET?

+3
4

jQuery.ajaxSubmit() jQuery.ajax(). , cache: false, :

jQuery(this).ajaxSubmit({
    cache: false,
    success: 
        function(data) {
            var response = $("<ol>"+data+"</ol>");
            response.find('.commentlist li:last').hide().appendTo(jQuery('.commentlist')).slideDown('slow');
        }           
    });
+2

, , - rand = new Date(). getTime()

if(url.replace("?") != url)
   url = url+"&rand="+new Date().getTime();
else
   url = url+"?rand="+new Date().getTime();

rand = url [ .php]. get, & rand = time... ? rand = , .

PHP header(), , Cache-control: Expires:

+1

php:

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

. - .

The message is redirected to the receipt request, and you will need to send some information to the receipt page to control whether it should be cached or not.

0
source

This will prevent global caching.

$(document).ready(function() {
     $.ajaxSetup({ cache: false });
});
0
source

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


All Articles