FAQ Topic - Why is my AJAX page not updated properly when using an HTTP GET request in Internet Expl

Discussion in 'Javascript' started by FAQ server, Nov 23, 2007.

  1. FAQ server

    FAQ server Guest

    -----------------------------------------------------------------------
    FAQ Topic - Why is my AJAX page not updated properly when
    using an HTTP GET request in Internet Explorer?
    -----------------------------------------------------------------------

    Microsoft Internet Explorer caches the results of HTTP GET requests. To ensure that the
    document is retrieved from the server, you will need to use the POST Method.

    http://msdn2.microsoft.com/en-us/library/ms536648.aspx


    --
    Postings such as this are automatically sent once a day. Their
    goal is to answer repeated questions, and to offer the content to
    the community for continuous evaluation/improvement. The complete
    comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
    The FAQ workers are a group of volunteers. The sendings of these
    daily posts are proficiently hosted by http://www.pair.com.
     
    FAQ server, Nov 23, 2007
    #1
    1. Advertising

  2. FAQ server

    Guest

    Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    On Nov 23, 5:00 am, "FAQ server" <> wrote:
    > -----------------------------------------------------------------------
    > FAQ Topic - Why is my AJAX page not updated properly when
    > using an HTTP GET request in Internet Explorer?
    > -----------------------------------------------------------------------
    >
    > Microsoft Internet Explorer caches the results of HTTP GET requests. To ensure that the
    > document is retrieved from the server, you will need to use the POST Method.

    Either that or append a timestamp to your URL so that the results are
    not cached. It has worked for me. Something like:

    var url = 'action.do?t=' + (+new Date());
    xhr.open('get', url, true);
    xhr.send(null);
     
    , Nov 25, 2007
    #2
    1. Advertising

  3. Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    wrote:
    > On Nov 23, 5:00 am, "FAQ server" <> wrote:
    >> -----------------------------------------------------------------------
    >> FAQ Topic - Why is my AJAX page not updated properly when
    >> using an HTTP GET request in Internet Explorer?
    >> -----------------------------------------------------------------------
    >>
    >> Microsoft Internet Explorer caches the results of HTTP GET requests. To ensure that the
    >> document is retrieved from the server, you will need to use the POST Method.

    > Either that or append a timestamp to your URL so that the results are
    > not cached. It has worked for me. Something like:
    >
    > var url = 'action.do?t=' + (+new Date());
    > xhr.open('get', url, true);
    > xhr.send(null);


    That is only required for people who have servers that cannot
    provide cache-controlling headers. Search the archives.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Nov 25, 2007
    #3
  4. FAQ server

    Guest

    Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    On Nov 25, 7:13 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > > var url = 'action.do?t=' + (+new Date());
    > > xhr.open('get', url, true);
    > > xhr.send(null);

    >
    > That is only required for people who have servers that cannot
    > provide cache-controlling headers. Search the archives.
    >
    > PointedEars


    So does this mean that what is specified in the FAQ and my me can be
    easily corrected by setting the relevant cache headers in the response
    header? I mean something like: response.setHeader("Cache-Control", "no-
    cache") ?

    Thanks and regards,
    /~STS
     
    , Nov 26, 2007
    #4
  5. Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    wrote:
    > On Nov 25, 7:13 pm, Thomas 'PointedEars' Lahn <>
    > wrote:
    >>> var url = 'action.do?t=' + (+new Date());
    >>> xhr.open('get', url, true);
    >>> xhr.send(null);

    >> That is only required for people who have servers that cannot
    >> provide cache-controlling headers. Search the archives.

    >
    > So does this mean that what is specified in the FAQ and my me can be
    > easily corrected by setting the relevant cache headers in the response
    > header? I mean something like: response.setHeader("Cache-Control", "no-
    > cache") ?


    Yes, it can.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Nov 26, 2007
    #5
  6. Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    On Nov 25, 5:47 am, wrote:
    > On Nov 23, 5:00 am, "FAQ server" <> wrote:> -----------------------------------------------------------------------
    > > FAQ Topic - Why is my AJAX page not updated properly when
    > > using an HTTP GET request in Internet Explorer?
    > > -----------------------------------------------------------------------

    >
    > > Microsoft Internet Explorer caches the results of HTTP GET requests. To ensure that the
    > > document is retrieved from the server, you will need to use the POST Method.

    >
    > Either that or append a timestamp to your URL so that the results are
    > not cached. It has worked for me. Something like:
    >
    > var url = 'action.do?t=' + (+new Date());


    I have a vague memory that this is not necessarily sufficient because
    the browser doesn't necessarily look at the query string when
    determining whether or not to use the cache.

    Better is to have the timestamp as part of the URL before the query
    string

    var url = 'action-' + (new Date()) + '.do';

    The above is a good idea for static files like .js and .css where you
    want to cache the files but then you want to have new versions
    download.

    For Ajax responses, if controlling the response headers with no-cache
    is possible then it seems to be the most natural way to do things.

    Peter
     
    Peter Michaux, Nov 26, 2007
    #6
  7. Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    Peter Michaux wrote:
    > On Nov 25, 5:47 am, wrote:
    >> On Nov 23, 5:00 am, "FAQ server" <> wrote:
    >>> -----------------------------------------------------------------------
    >>> FAQ Topic - Why is my AJAX page not updated properly when using an
    >>> HTTP GET request in Internet Explorer?
    >>> -----------------------------------------------------------------------
    >>> Microsoft Internet Explorer caches the results of HTTP GET requests.
    >>> To ensure that the document is retrieved from the server, you will
    >>> need to use the POST Method.

    >> Either that or append a timestamp to your URL so that the results are
    >> not cached. It has worked for me. Something like:
    >>
    >> var url = 'action.do?t=' + (+new Date());

    >
    > I have a vague memory that this is not necessarily sufficient because the
    > browser doesn't necessarily look at the query string when determining
    > whether or not to use the cache.


    With all due respect: user agents this broken do not deserve to be supported.

    > Better is to have the timestamp as part of the URL before the query
    > string
    >
    > var url = 'action-' + (new Date()) + '.do';
    >
    > The above is a good idea for static files like .js and .css where you
    > want to cache the files but then you want to have new versions download.


    However, it would require server-side URL rewrite.

    > For Ajax responses, if controlling the response headers with no-cache is
    > possible then it seems to be the most natural way to do things.


    Exactly.


    PointedEars
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Nov 26, 2007
    #7
  8. Peter Michaux wrote:
    > On Nov 25, 5:47 am, wrote:

    <snip>
    >> Either that or append a timestamp to your URL so that the
    >> results are not cached. It has worked for me. Something like:
    >>
    >> var url = 'action.do?t=' + (+new Date());

    >
    > I have a vague memory that this is not necessarily sufficient
    > because the browser doesn't necessarily look at the query
    > string when determining whether or not to use the cache.


    That would be an inaccurate or false memory, or a memory of an unsubstantiated claim made by
    someone who did not know what they were talking about. The query string for a GET request is
    part of the URL and caching must consider the full URL in order to be operating correctly. I
    have previously posted the relevant parts of the HTTP 1.1 specification in response to this
    common misconception.

    > For Ajax responses, if controlling the response headers
    > with no-cache is possible then it seems to be the most
    > natural way to do things.


    It is difficult to envision an environment where such control was not possible (except for toy
    ''web space' provided to users as part of their ISP account).

    Richard.
     
    Richard Cornford, Nov 26, 2007
    #8
  9. Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    On Nov 26, 3:12 pm, "Richard Cornford" <>
    wrote:
    > Peter Michaux wrote:


    > > For Ajax responses, if controlling the response headers
    > > with no-cache is possible then it seems to be the most
    > > natural way to do things.

    >
    > It is difficult to envision an environment where such control was not possible


    It depends greatly on the server-side programmers involved ;-)

    Peter
     
    Peter Michaux, Nov 27, 2007
    #9
  10. FAQ server

    Guest

    Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    On Nov 27, 3:53 am, Thomas 'PointedEars' Lahn <>
    wrote:
    > > Better is to have the timestamp as part of the URL before the query
    > > string

    >
    > > var url = 'action-' + (new Date()) + '.do';

    >
    > > The above is a good idea for static files like .js and .css where you
    > > want to cache the files but then you want to have new versions download.

    >
    > However, it would require server-side URL rewrite.

    So does it mean that each time a request comes from the client, I
    would have to filter out the real URL / action URL before using it by
    employing a mechanism like ServletFilter?

    Thanks and regards,
    /~STS
     
    , Nov 27, 2007
    #10
  11. Re: FAQ Topic - Why is my AJAX page not updated properly when usingan HTTP GET request in Internet Explorer? (2007-11-23)

    wrote:
    > On Nov 27, 3:53 am, Thomas 'PointedEars' Lahn <>
    > wrote:
    >>> Better is to have the timestamp as part of the URL before the query
    >>> string
    >>> var url = 'action-' + (new Date()) + '.do';
    >>> The above is a good idea for static files like .js and .css where you
    >>> want to cache the files but then you want to have new versions download.

    >> However, it would require server-side URL rewrite.

    >
    > So does it mean that each time a request comes from the client, I
    > would have to filter out the real URL / action URL before using it by
    > employing a mechanism like ServletFilter?


    I don't know ServletFilter, but with Apache you would have to define
    something along

    RewriteEngine on
    RewriteRule ^(.*/[^-]+)-\d{13,}(.*)$ $1$2 [last]


    PointedEars

    P.S.
    Please include an empty line between quoted text and your text;
    that makes your postings easier legible.
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
     
    Thomas 'PointedEars' Lahn, Nov 27, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,994
    Smokey Grindel
    Dec 2, 2006
  2. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    416
    Dmitry Korolyov
    Sep 22, 2003
  3. Johannes Kleese
    Replies:
    4
    Views:
    264
    Terry Reedy
    Nov 27, 2012
  4. Cameron Simpson
    Replies:
    0
    Views:
    181
    Cameron Simpson
    Nov 12, 2012
  5. Terry Reedy
    Replies:
    0
    Views:
    358
    Terry Reedy
    Nov 13, 2012
Loading...

Share This Page