IT_Programming/JavaScript

[JQuery] Ajax IE 캐싱 문제

JJun ™ 2011. 4. 3. 12:52

jquery timer플러그인을 이용해 10초 마다 서버쪽으로 ajax request를 보내는 코드가 있었는데

이상하게 IE에서는 불특정하게 서버쪽으로  request가 나가지 않았다. (파폭에서는 이상없음)

$(function() {
    $(document).everyTime('10000', "AAAThread", function() {
        $.get("/blahblahblah.do",
                    {
                      "parm1": $("#parm1").val()        
                    }, callbackfunction,"json");
    });
});


callbackfunction은 호출이 되는데 blahblahblah.do 로 리퀘스트가 넘어가지 않았다.

즉, IE가 캐쉬를 가져온 것이다. 구글링을 통해 검색해 보니 IE에서 ajax콜이 캐쉬를 가져오는 문제가 있는 것 같고 가장 빠른 해결책은 post 방식을 사용하는 것이었다. 다른 해결책이 있는지도 모르겠지만

일단 위의 코드를 post방식으로 바꿔서 캐슁문제를 해결할 수 있었다.

$(function() {
    $(document).everyTime('10000', "AAAThread", function() {
        $.post("/blahblahblah.do",
                    {
                      "parm1": $("#parm1").val()        
                    }, callbackfunction,"json");
    });
});



 

더보기
URL: http://ajaxian.com/archives/ajax-ie-caching-issue 

Ajax IE Caching Issue

 

David Arthur, like many, has had problems with the caching issue that Internet Explorer seems to have with Ajax connections:

 

If you’ve been working with the Ajax framework long enough, i’m sure you’ve run into at least a few speed bumps thanks to Internet Explorer. Not a day goes by that i don’t have to rewrite a line of code, or tweak my css in order for IE to render what i think it should. But alas, this is the nature of software that comes from a company that views Standard Compliances as recommendations.

 

He describes his problem – grabbing a new image with an Aajx request, a seemingly simple task – and the results of his queries. IE decided caching it was the “in” thing and wasn’t going to grab anything new. He tried all sorts of hacks and fixes to try to get things working, but to no avail. Finally, after finding this entry on Wikipedia, he stumbled across a solution – using POST over GET.

 

While he was figuring it out, though, there were also lots of comments being made to the original post with hacks to get around the issue – so many that he wanted to create a new place for them all to be shared. In this post he includes two of the suggestions, including using something like a timestamp to change up the URL and adding in an unused POST variable.