.error(function(){ ok(false, "error"); })
.complete(function(){ start(); });
}
- })
+ });
}, 13);
});
.complete(function(){ start(); });
},100);
}
- })
+ });
}, 13);
});
});
});
+test("jQuery.ajax() - responseText on error", function() {
+
+ expect( 1 );
+
+ stop();
+
+ jQuery.ajax({
+ url: url("data/errorWithText.php"),
+ error: function(xhr) {
+ strictEqual( xhr.responseText , "plain text message" , "Test jXHR.responseText is filled for HTTP errors" );
+ },
+ complete: function() {
+ start();
+ }
+ });
+});
+
+test(".ajax() - retry with jQuery.ajax( this )", function() {
+
+ expect( 1 );
+
+ stop();
+
+ var firstTime = 1;
+
+ jQuery.ajax({
+ url: url("data/errorWithText.php"),
+ error: function() {
+ if ( firstTime ) {
+ firstTime = 0;
+ jQuery.ajax( this );
+ } else {
+ ok( true , "Test retrying with jQuery.ajax(this) works" );
+ start();
+ }
+ }
+ })
+
+});
+
test(".ajax() - headers" , function() {
expect( 2 );
});
+test(".ajax() - contentType" , function() {
+
+ expect( 2 );
+
+ stop();
+
+ var count = 2;
+
+ function restart() {
+ if ( ! --count ) {
+ start();
+ }
+ }
+
+ jQuery.ajax(url("data/headers.php?keys=content-type" ), {
+ contentType: "test",
+ success: function( data ) {
+ strictEqual( data , "content-type: test\n" , "Test content-type is sent when options.contentType is set" );
+ },
+ complete: function() {
+ restart();
+ }
+ });
+
+ jQuery.ajax(url("data/headers.php?keys=content-type" ), {
+ contentType: false,
+ success: function( data ) {
+ strictEqual( data , "content-type: \n" , "Test content-type is not sent when options.contentType===false" );
+ },
+ complete: function() {
+ restart();
+ }
+ });
+
+});
+
test(".ajax() - hash", function() {
expect(3);
});
});
+test("jQuery ajax - cross-domain detection", function() {
+
+ expect( 4 );
+
+ var loc = document.location,
+ otherPort = loc.port === 666 ? 667 : 666,
+ otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
+
+ jQuery.ajax({
+ dataType: "jsonp",
+ url: otherProtocol + "//" + loc.host,
+ beforeSend: function( _ , s ) {
+ ok( s.crossDomain , "Test different protocols are detected as cross-domain" );
+ return false;
+ }
+ });
+
+ jQuery.ajax({
+ dataType: "jsonp",
+ url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
+ beforeSend: function( _ , s ) {
+ ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
+ return false;
+ }
+ });
+
+ jQuery.ajax({
+ dataType: "jsonp",
+ url: loc.protocol + "//" + loc.hostname + ":" + otherPort,
+ beforeSend: function( _ , s ) {
+ ok( s.crossDomain , "Test different ports are detected as cross-domain" );
+ return false;
+ }
+ });
+
+ jQuery.ajax({
+ dataType: "jsonp",
+ url: loc.protocol + "//" + loc.host,
+ crossDomain: true,
+ beforeSend: function( _ , s ) {
+ ok( s.crossDomain , "Test forced crossDomain is detected as cross-domain" );
+ return false;
+ }
+ });
+
+});
+
test(".ajax() - 304", function() {
expect( 1 );
stop();
stop();
- var obj = {}
+ var obj = {};
jQuery.ajax({
url: url("data/name.html"),
equals( result, "key=value" );
start();
}
- })
+ });
});
test("data option: empty bodies for non-GET requests", function() {
equals( result, "" );
start();
}
- })
+ });
});
test("jQuery.ajax - If-Modified-Since support", function() {
ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
} else {
equals(status, "notmodified");
- ok(data == null, "response body should be empty")
+ ok(data == null, "response body should be empty");
}
start();
},
ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
} else {
equals(status, "notmodified");
- ok(data == null, "response body should be empty")
+ ok(data == null, "response body should be empty");
}
start();
},