Welcome Guest, Not a member yet? Register   Sign In
Jquery & Codeigniter ajax cache: false
#1

[eluser]mjsilva[/eluser]
Hi there,

TIL that Internet Explorer caches every ajax call, even if you do something like this:

Code:
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
$this->output->set_header('Expires: '.gmdate('D, d M Y H:i:s', time()).' GMT');
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");

In Jquery you can specify this:

Code:
$.ajaxSetup({
    cache: false
});

This is a smart thing, what it do is putting a timestamp in your request, so let's say you have this function:
Code:
$("#checkout").click(function(){
    var self = $(this);
    $.get(base_url+'ajax_fnc/is_logged_in/', function(data){
        alert(data);
        if(!data)
        {
            $("#login_btn").click();
            $('html, body').animate({scrollTop:0}, 'normal');
        }
        else
        {
            [removed] = self.attr('href');
        }
    });

    return false;
});

Your request becomes:

http://my_site.com/ajax_fnc/is_logged_in/?_=1274699621534

But codeigniter doesn't appears to like this type of URLs, I've already make this changes in config.php:
Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-&=';
$config['enable_query_strings'] = TRUE;

but I'm still getting 404 errors.

Any hint on how to prevent Internet Explorer to cache this type of ajax calls?
Or how to make CI to like this URL?

tks
#2

[eluser]zoko2902[/eluser]
you can try using the post method, since it's not supposed to be cached.
#3

[eluser]mjsilva[/eluser]
Yes, I ended doing that.

But it's one of those things, that I would like to know why it happens, like magnets Smile
#4

[eluser]zoko2902[/eluser]
I know what you mean Big Grin.

I was banging my head with this IE "feature" couple of months ago. It was explained rather clearly in this post.




Theme © iAndrew 2016 - Forum software by © MyBB