Fixes 4825. jQuery.fn.load: use the jXHR's Promise interface to get the actual respon...
[jquery.git] / test / unit / ajax.js
index 4c8c500..1b55402 100644 (file)
@@ -383,53 +383,48 @@ test(".ajax() - hash", function() {
 
 test("jQuery ajax - cross-domain detection", function() {
 
-       expect( 3 );
+       expect( 4 );
 
        var loc = document.location,
                otherPort = loc.port === 666 ? 667 : 666,
-               otherProtocol = loc.protocol === "http:" ? "https:" : "http:",
-               protocolFlag,
-               hostFlag,
-               portFlag;
+               otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
 
-       if ( jQuery.ajax({
+       jQuery.ajax({
+               dataType: "jsonp",
                url: otherProtocol + "//" + loc.host,
                beforeSend: function( _ , s ) {
-                       protocolFlag = 1;
                        ok( s.crossDomain , "Test different protocols are detected as cross-domain" );
                        return false;
                }
-       }) === false ) {
-               if ( ! protocolFlag ) {
-                       ok( ! jQuery.support.cors , "Test different protocols are detected as cross-domain (no transport)" );
-               }
-       }
+       });
 
-       if ( jQuery.ajax({
+       jQuery.ajax({
+               dataType: "jsonp",
                url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
                beforeSend: function( _ , s ) {
-                       hostFlag = 1;
                        ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
                        return false;
                }
-       }) === false ) {
-               if ( ! hostFlag ) {
-                       ok( ! jQuery.support.cors , "Test different hostnames are detected as cross-domain (no transport)" );
-               }
-       }
+       });
 
-       if ( jQuery.ajax({
+       jQuery.ajax({
+               dataType: "jsonp",
                url: loc.protocol + "//" + loc.hostname + ":" + otherPort,
                beforeSend: function( _ , s ) {
-                       portFlag = 1;
                        ok( s.crossDomain , "Test different ports are detected as cross-domain" );
                        return false;
                }
-       }) === false ) {
-               if ( ! portFlag ) {
-                       ok( ! jQuery.support.cors , "Test different ports are detected as cross-domain (no transport)" );
+       });
+
+       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;
                }
-       }
+       });
 
 });
 
@@ -1030,6 +1025,18 @@ test("load(String, Function) - check file with only a script tag", function() {
        });
 });
 
+test("load(String, Function) - dataFilter in ajaxSettings", function() {
+       expect(2);
+       stop();
+       jQuery.ajaxSetup({ dataFilter: function() { return "Hello World"; } });
+       var div = jQuery("<div/>").load(url("data/name.html"), function(responseText) {
+               strictEqual( div.html(), "Hello World" , "Test div was filled with filtered data" );
+               strictEqual( responseText, "Hello World" , "Test callback receives filtered data" );
+               jQuery.ajaxSetup({ dataFilter: 0 });
+               start();
+       });
+});
+
 test("load(String, Object, Function)", function() {
        expect(2);
        stop();
@@ -1086,10 +1093,10 @@ test("jQuery.getScript(String, Function) - no callback", function() {
 });
 
 test("jQuery.ajax() - JSONP, Local", function() {
-       expect(9);
+       expect(10);
 
        var count = 0;
-       function plus(){ if ( ++count == 9 ) start(); }
+       function plus(){ if ( ++count == 10 ) start(); }
 
        stop();
 
@@ -1136,6 +1143,22 @@ test("jQuery.ajax() - JSONP, Local", function() {
        jQuery.ajax({
                url: "data/jsonp.php",
                dataType: "jsonp",
+               data: {
+                       callback: "?"
+               },
+               success: function(data){
+                       ok( data.data, "JSON results returned (GET, processed data callback)" );
+                       plus();
+               },
+               error: function(data){
+                       ok( false, "Ajax error JSON (GET, processed data callback)" );
+                       plus();
+               }
+       });
+
+       jQuery.ajax({
+               url: "data/jsonp.php",
+               dataType: "jsonp",
                jsonp: "callback",
                success: function(data){
                        ok( data.data, "JSON results returned (GET, data obj callback)" );