Bug Tracker

Opened 10 years ago

Closed 9 years ago

#6518 closed bug (invalid)

.ajax() ifModified option -- behaviour changed in v1.4.2

Reported by: rsinton Owned by:
Priority: undecided Milestone: 1.4.3
Component: ajax Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

Description

As described by jQuery forum user alxblog, the ifModified option seems to have stopped working between v1.3.2 and v1.4.2.

Forum posting with good sample code: http://forum.jquery.com/topic/jquery-1-3-2-update-to-1-4-2-ifmodified-option-doesn-t-still-work

The sample code works as expected in v1.3.2, delivering "notmodified" as the textStatus parameter to the .ajax() call's error function. This matches the behaviour described in the documentation for .ajax().

In v1.4.2, however, the success function is called every time.

I can see that the relevant jQuery code for this functionality has changed quite a bit between those versions. Looks like the problem is here:

Make sure that the request was successful or notmodified

if ( status === "success"
status === "notmodified" ) {

JSONP handles its own success callback if ( !jsonp ) {

success();

}

} else {

jQuery.handleError(s, xhr, status, errMsg);

}

i.e. "notmodified" is now being treated as a success rather than an error.

Attachments (2)

test30.html (785 bytes) - added by rsinton 10 years ago.
Sample Code
Loaded.php (161 bytes) - added by rsinton 10 years ago.
Loaded.php (called by ajax function)

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by rsinton

Attachment: test30.html added

Sample Code

Changed 10 years ago by rsinton

Attachment: Loaded.php added

Loaded.php (called by ajax function)

comment:1 Changed 10 years ago by rsinton

Oops, sorry. Properly-formatted code this time:

// Make sure that the request was successful or notmodified
if ( status === "success" || status === "notmodified" ) {
    // JSONP handles its own success callback
    if ( !jsonp ) {
        success();
    }
} else {
    jQuery.handleError(s, xhr, status, errMsg);
}

comment:2 Changed 10 years ago by rsinton

Update: I think the issue is actually not there, but in the change to the httpNotModified function.

Final return in v1.3.2 was:

return xhr.status == 304 || xhrRes == jQuery.lastModified[url];

but is now:

return xhr.status === 304 || xhr.status === 0;

i.e. only xhr.status is being tested.

Debugging in Safari, I find that the xhr.status is 200 at this point, but

xhr.getResponseHeader("Last-Modified") == jQuery.lastModified[s.url]

does evaluate true.

comment:3 Changed 10 years ago by rsinton

Ah, mea culpa. I have just realised that the sample code is returning the last-modified date, but not returning an HTTP 304 status code.

It is a change in behaviour vs v1.3.2, but if I expect that v1.4.2 is actually taking a more correct approach.

Please close.

comment:4 Changed 9 years ago by addyosmani

Priority: undecided
Resolution: invalid
Status: newclosed

Closing as this issue has been resolved in 1.4.2. ifModified hasn't stopped working but has actually been updated appropriately since the 1.3.2 release. I believe the original ticket submitter was looking at an incorrect output in their example which may have prompted the original look at ifModified's behaviour.

Note: See TracTickets for help on using tickets.