I think in some situations, the XmlHttpRequest returns a status of 304 and
at the same time provide the responseText or XML.

http://prototype.lighthouseapp.com/projects/8886/tickets/331-status-304-not-checked-for-onsuccess-for-ajaxrequest

 status 304 not checked for onSuccess for Ajax.Request

Reported by Kenneth Kin Lum
<http://prototype.lighthouseapp.com/users/18343>| September 9th, 2008
@ 10:08 AM

it seems that prototype.js will consider the status >= 200 && < 300 as
success. The status 304 is not checked, while there are 3 rather
authoritative books that says Opera and some version of IE will return a
status of 304 together with responseText or responseXML populated (even
thought the HTTP response doesn't have the data part in the case of 304).
These books are:

Bulletproof Ajax by Jeremy Keith

Professional Ajax, 2nd Edition (Programmer to Programmer) by Nicholas C.
Zakas, Jeremy McPeak, and Joe Fawcett

Building a Web Site with Ajax: Visual QuickProject Guide by Larry Ullman

(can download their sample code or try their sample website and see their
source code)

So I wonder, if the 304 is not considered, then there might be possibility
of user clicking on a link and ajax invoked, but onSuccess doesn't catch it,
when the status is 304. Thanks very much. (prototype is great by the way)
-

actually, one more

Pro JavaScript Techniques (Pro) by John Resig

p. 223

it also checks for Safari returning status which is undefined.

i got curious to what jquery does and saw this:

httpSuccess: function( xhr ) {
    try {
        // IE error sometimes returns 1223 when it should be 204 so
treat it as success, see [#1450](/projects/8886/tickets/1450 "Ticket
#1450")
        return !xhr.status && location.protocol == "file:" ||
            ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status ==
304 || xhr.status == 1223 ||
            jQuery.browser.safari && xhr.status == undefined;
    } catch(e){}
    return false;
},








On Tue, Sep 9, 2008 at 1:04 AM, T.J. Crowder <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> > In the currently latest version of prototype.js
> > ...
> > there is no def for onSuccess?  yet when I use
> >
> > Ajax.Request(url, { onSuccess : function(r) { ... }    it works...
> >
> > So is it defined some where else?
>
> Yes, *you're* defining it (above).  Prototype calls it.
>
> > I was mainly looking for the conditions of success, because Jeremy
> > Keith in his book Bulletproof AJAX says that the status of 200 and 304
> > both should be considered a success.
> > ...
> > There is a check in prototype
> > ...
> > but it doesn't include 304.  Does someone know?  Many thanks!
>
> I'd never thought about 304.  304 (for anyone else reading this who
> hasn't memorized HTTP response codes) is the "not modified" response,
> meaning a conditional GET has been performed and the local copy is
> still fresh:
> http://www.w3.org/Protocols/rfc2616/rfc2616.html
> Response 304 is not allowed to contain a body; the point is to get the
> body from cache if you see a 304.
>
> It appears that most browsers translate a 304 into a 200 and supply
> the cached body for our code, which I (for one) greatly appreciate,
> that seems like the appropriate layer to handle that as they will have
> the cache and we won't. :-)  I found this interesting page:
> http://www.mnot.net/javascript/xmlhttprequest/cache.html
> ...which says it tests caching and XHR on the browser you're using,
> and has a specific test for this 304 situation.  I tested a few using
> it:  IE6, FF3, and Safari 3.1 for Windows all translated the 304 into
> a 200 nicely.  The test failed on Opera 9 (says it got back a status
> code of 0), but whether that indicates a problem with Opera 9 or the
> author's testing code I haven't looked into.
>
> liketofindoutwhy:  (Do you have a name?)  If you google
> "httpxmlrequest 304" (without the quotes), you'll find lots of
> discussion of the 304 vs. 200 issue.
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
>
> On Sep 9, 12:31 am, liketofindoutwhy <[EMAIL PROTECTED]>
> wrote:
> > In the currently latest version of prototype.js
> >
> > http://www.prototypejs.org/assets/2008/1/25/prototype-1.6.0.2.js
> >
> > there is no def for onSuccess?  yet when I use
> >
> > Ajax.Request(url, { onSuccess : function(r) { ... }    it works...
> >
> > So is it defined some where else?
> >
> > I was mainly looking for the conditions of success, because Jeremy
> > Keith in his book Bulletproof AJAX says that the status of 200 and 304
> > both should be considered a success.  He says some version of Opera
> > does a conditional GET to check whether the page in cache is up to
> > date, and if it is, then the status 304 is returned instead of 200.
> >
> > Thought, when I try the latest version of Opera using the most basic
> > form of AJAX (XmlHttpRequest or the Microsoft ActiveX), then I only
> > see a 200 status, never a 304.
> >
> > There is a check in prototype
> >
> >   success: function() {
> >     var status = this.getStatus();
> >     return !status || (status >= 200 && status < 300);
> >   },
> >
> > but it doesn't include 304.  Does someone know?  Many thanks!
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to