Skip to content

Commit ba9e0fc

Browse files
committed
Use a different workaround for detecting when Opera finds a status 304 page. Fixes #6060.
1 parent 3a0a352 commit ba9e0fc

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/ajax.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,11 @@ jQuery.extend( jQuery.ajax, {
629629
try {
630630
// IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
631631
return !xhr.status && location.protocol === "file:" ||
632-
// Opera returns 0 when status is 304
633632
( xhr.status >= 200 && xhr.status < 300 ) ||
634-
xhr.status === 304 || xhr.status === 1223 || xhr.status === 0;
633+
xhr.status === 304 || xhr.status === 1223 ||
634+
// Opera returns a status of 0 for redirects -
635+
// We can detect this by the fact that Opera also doesn't return any headers
636+
xhr.status === 0 && !xhr.getAllResponseHeaders();
635637
} catch(e) {}
636638

637639
return false;
@@ -651,7 +653,7 @@ jQuery.extend( jQuery.ajax, {
651653
}
652654

653655
// Opera returns 0 when status is 304
654-
return xhr.status === 304 || xhr.status === 0;
656+
return xhr.status === 304 || xhr.status === 0 && !xhr.getAllResponseHeaders();
655657
},
656658

657659
httpData: function( xhr, type, s ) {

test/data/notmodified.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php header('HTTP/1.0 304 Not Modified'); exit; ?>

test/unit/ajax.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ test("jQuery.ajax() - error callbacks", function() {
6868
});
6969
});
7070

71+
test(".ajax() - 304", function() {
72+
expect( 1 );
73+
stop();
74+
75+
jQuery.ajax({
76+
url: url("data/notmodified.php"),
77+
success: function(){ ok(true, "304 ok"); },
78+
error: function(){ ok(false, "304 not ok "); },
79+
complete: function(xhr){ start(); }
80+
});
81+
});
82+
7183
test(".load()) - 404 error callbacks", function() {
7284
expect( 6 );
7385
stop();

0 commit comments

Comments
 (0)