Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jquery/jquery
base: master
...
head fork: plukevdh/jquery
compare: master
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 14, 2011
@plukevdh plukevdh two more callbacks available for XHR support
LOADING and HEADERS_RECEIVED states supported.
33e681c
@plukevdh plukevdh add specs ad0f696
Showing with 28 additions and 9 deletions.
  1. +9 −2 src/ajax/xhr.js
  2. +19 −7 test/unit/ajax.js
View
11 src/ajax/xhr.js
@@ -118,9 +118,16 @@ if ( jQuery.support.ajax ) {
// http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE)
try {
- // Was never called and is aborted or complete
- if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
+ // The readystate 2, HEADERS_RECEIVED
+ if ( callback && !isAbort && xhr.readyState === 2 && s.receivedHeaders ) {
+ s.receivedHeaders.call( s.context, xhr );
+
+ // The readystate 3, LOADING
+ } else if ( callback && !isAbort && xhr.readyState === 3 && s.loading ) {
+ s.loading.call( s.context, xhr );
+ // Was never called and is aborted or complete
+ } else if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
// Only called once
callback = undefined;
View
26 test/unit/ajax.js
@@ -8,7 +8,7 @@ module("ajax", { teardown: moduleTeardown });
if ( !isLocal ) {
test("jQuery.ajax() - success callbacks", function() {
- expect( 8 );
+ expect( 10 );
jQuery.ajaxSetup({ timeout: 0 });
@@ -32,6 +32,8 @@ test("jQuery.ajax() - success callbacks", function() {
jQuery.ajax({
url: url("data/name.html"),
beforeSend: function(){ ok(true, "beforeSend"); },
+ receivedHeaders: function(){ ok(true, "receivedHeaders"); },
+ loading: function(){ ok(true, "loading"); },
success: function(){ ok(true, "success"); },
error: function(){ ok(false, "error"); },
complete: function(){ ok(true, "complete"); }
@@ -39,7 +41,7 @@ test("jQuery.ajax() - success callbacks", function() {
});
test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
- expect( 8 );
+ expect( 10 );
jQuery.ajaxSetup({ timeout: 0 });
@@ -63,6 +65,8 @@ test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
jQuery.ajax( url("data/name.html") , {
beforeSend: function(){ ok(true, "beforeSend"); },
+ receivedHeaders: function(){ ok(true, "receivedHeaders"); },
+ loading: function(){ ok(true, "loading"); },
success: function(){ ok(true, "success"); },
error: function(){ ok(false, "error"); },
complete: function(){ ok(true, "complete"); }
@@ -71,7 +75,7 @@ test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
});
test("jQuery.ajax() - success callbacks (late binding)", function() {
- expect( 8 );
+ expect( 10 );
jQuery.ajaxSetup({ timeout: 0 });
@@ -95,7 +99,9 @@ test("jQuery.ajax() - success callbacks (late binding)", function() {
jQuery.ajax({
url: url("data/name.html"),
- beforeSend: function(){ ok(true, "beforeSend"); }
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ receivedHeaders: function(){ ok(true, "receivedHeaders"); },
+ loading: function(){ ok(true, "loading"); }
})
.complete(function(){ ok(true, "complete"); })
.success(function(){ ok(true, "success"); })
@@ -104,7 +110,7 @@ test("jQuery.ajax() - success callbacks (late binding)", function() {
});
test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
- expect( 8 );
+ expect( 10 );
jQuery.ajaxSetup({ timeout: 0 });
@@ -128,6 +134,8 @@ test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
jQuery.ajax({
url: url("data/name.html"),
beforeSend: function(){ ok(true, "beforeSend"); },
+ receivedHeaders: function(){ ok(true, "receivedHeaders"); },
+ loading: function(){ ok(true, "loading"); },
complete: function(xhr) {
xhr
.complete(function(){ ok(true, "complete"); })
@@ -140,7 +148,7 @@ test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
});
test("jQuery.ajax() - success callbacks (very late binding)", function() {
- expect( 8 );
+ expect( 10 );
jQuery.ajaxSetup({ timeout: 0 });
@@ -164,6 +172,8 @@ test("jQuery.ajax() - success callbacks (very late binding)", function() {
jQuery.ajax({
url: url("data/name.html"),
beforeSend: function(){ ok(true, "beforeSend"); },
+ receivedHeaders: function(){ ok(true, "receivedHeaders"); },
+ loading: function(){ ok(true, "loading"); },
complete: function(xhr) {
setTimeout (function() {
xhr
@@ -211,7 +221,7 @@ test("jQuery.ajax() - success callbacks (order)", function() {
});
test("jQuery.ajax() - error callbacks", function() {
- expect( 8 );
+ expect( 10 );
stop();
jQuery("#foo").ajaxStart(function(){
@@ -234,6 +244,8 @@ test("jQuery.ajax() - error callbacks", function() {
jQuery.ajax({
url: url("data/name.php?wait=5"),
beforeSend: function(){ ok(true, "beforeSend"); },
+ receivedHeaders: function(){ ok(true, "receivedHeaders"); },
+ loading: function(){ ok(true, "loading"); },
success: function(){ ok(false, "success"); },
error: function(){ ok(true, "error"); },
complete: function(){ ok(true, "complete"); }

No commit comments for this range

Something went wrong with that request. Please try again.