Build: Move test to appropriate module
[jquery.git] / test / unit / ajax.js
blob868f19bc824a170d5eacc5dd9cf224c7e898989c
1 module( "ajax", {
2         setup: function() {
3                 var jsonpCallback = this.jsonpCallback = jQuery.ajaxSettings.jsonpCallback;
4                 jQuery.ajaxSettings.jsonpCallback = function() {
5                         var callback = jsonpCallback.apply( this, arguments );
6                         Globals.register( callback );
7                         return callback;
8                 };
9         },
10         teardown: function() {
11                 jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
12                 moduleTeardown.apply( this, arguments );
13         }
14 });
16 (function() {
17         test("Unit Testing Environment", 2, function () {
18                 ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" );
19                 ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" );
20         });
22         if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) {
23                 return;
24         }
26         function addGlobalEvents( expected ) {
27                 return function() {
28                         expected = expected || "";
29                         jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) {
30                                 ok( expected.indexOf(e.type) !== -1, e.type );
31                         });
32                 };
33         }
35 //----------- jQuery.ajax()
37         ajaxTest( "jQuery.ajax() - success callbacks", 8, {
38                 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
39                 url: url("data/name.html"),
40                 beforeSend: function() {
41                         ok( true, "beforeSend" );
42                 },
43                 success: function() {
44                         ok( true, "success" );
45                 },
46                 complete: function() {
47                         ok( true, "complete");
48                 }
49         });
51         ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, {
52                 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
53                 create: function( options ) {
54                         return jQuery.ajax( url("data/name.html"), options );
55                 },
56                 beforeSend: function() {
57                         ok( true, "beforeSend" );
58                 },
59                 success: function() {
60                         ok( true, "success" );
61                 },
62                 complete: function() {
63                         ok( true, "complete" );
64                 }
65         });
67         ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, {
68                 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
69                 url: url("data/name.html"),
70                 beforeSend: function() {
71                         ok( true, "beforeSend" );
72                 },
73                 success: true,
74                 afterSend: function( request ) {
75                         request.complete(function() {
76                                 ok( true, "complete" );
77                         }).success(function() {
78                                 ok( true, "success" );
79                         }).error(function() {
80                                 ok( false, "error" );
81                         });
82                 }
83         });
85         ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, {
86                 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
87                 url: url("data/name.html"),
88                 beforeSend: function() {
89                         ok( true, "beforeSend" );
90                 },
91                 success: true,
92                 complete: function( xhr ) {
93                         xhr.complete(function() {
94                                 ok( true, "complete" );
95                         }).success(function() {
96                                 ok( true, "success" );
97                         }).error(function() {
98                                 ok( false, "error" );
99                         });
100                 }
101         });
103         ajaxTest( "jQuery.ajax() - error callbacks", 8, {
104                 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError"),
105                 url: url("data/name.php?wait=5"),
106                 beforeSend: function() {
107                         ok( true, "beforeSend" );
108                 },
109                 afterSend: function( request ) {
110                         request.abort();
111                 },
112                 error: function() {
113                         ok( true, "error" );
114                 },
115                 complete: function() {
116                         ok( true, "complete" );
117                 }
118         });
120         ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, [
121                 {
122                         url: url("data/name.php?wait=5"),
123                         error: function( _, textStatus, errorThrown ) {
124                                 strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
125                                 strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" );
126                         },
127                         afterSend: function( request ) {
128                                 request.abort();
129                         }
130                 },
131                 {
132                         url: url("data/name.php?wait=5"),
133                         error: function( _, textStatus, errorThrown ) {
134                                 strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
135                                 strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" );
136                         },
137                         afterSend: function( request ) {
138                                 request.abort("mystatus");
139                         }
140                 }
141         ]);
143         ajaxTest( "jQuery.ajax() - responseText on error", 1, {
144                 url: url("data/errorWithText.php"),
145                 error: function( xhr ) {
146                         strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" );
147                 }
148         });
150         asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function() {
151                 var previousUrl,
152                         firstTime = true;
153                 jQuery.ajax({
154                         url: url("data/errorWithText.php"),
155                         error: function() {
156                                 if ( firstTime ) {
157                                         firstTime = false;
158                                         jQuery.ajax( this );
159                                 } else {
160                                         ok ( true, "Test retrying with jQuery.ajax(this) works" );
161                                         jQuery.ajax({
162                                                 url: url("data/errorWithText.php"),
163                                                 data: {
164                                                         "x": 1
165                                                 },
166                                                 beforeSend: function() {
167                                                         if ( !previousUrl ) {
168                                                                 previousUrl = this.url;
169                                                         } else {
170                                                                 strictEqual( this.url, previousUrl, "url parameters are not re-appended" );
171                                                                 start();
172                                                                 return false;
173                                                         }
174                                                 },
175                                                 error: function() {
176                                                         jQuery.ajax( this );
177                                                 }
178                                         });
179                                 }
180                         }
181                 });
182         });
184         ajaxTest( "jQuery.ajax() - headers", 5, {
185                 setup: function() {
186                         jQuery( document ).ajaxSend(function( evt, xhr ) {
187                                 xhr.setRequestHeader( "ajax-send", "test" );
188                         });
189                 },
190                 url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send"),
191                 headers: {
192                         "siMPle": "value",
193                         "SometHing-elsE": "other value",
194                         "OthEr": "something else",
195                         "Nullable": null,
196                         "undefined": undefined
198                         // Support: Firefox
199                         // Not all browsers allow empty-string headers
200                         // https://bugzilla.mozilla.org/show_bug.cgi?id=815299
201                         //"Empty": ""
202                 },
203                 success: function( data, _, xhr ) {
204                         var i, emptyHeader,
205                                 requestHeaders = jQuery.extend( this.headers, {
206                                         "ajax-send": "test"
207                                 }),
208                                 tmp = [];
209                         for ( i in requestHeaders ) {
210                                 tmp.push( i, ": ", requestHeaders[ i ] + "", "\n" );
211                         }
212                         tmp = tmp.join("");
214                         strictEqual( data, tmp, "Headers were sent" );
215                         strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" );
216                         ok( data.indexOf( "undefined" ) < 0 , "Undefined header value was not sent" );
218                         emptyHeader = xhr.getResponseHeader("Empty-Header");
219                         if ( emptyHeader === null ) {
220                                 ok( true, "Firefox doesn't support empty headers" );
221                         } else {
222                                 strictEqual( emptyHeader, "", "Empty header received" );
223                         }
224                         strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" );
225                 }
226         });
228         ajaxTest( "jQuery.ajax() - Accept header", 1, {
229                 url: url("data/headers.php?keys=accept"),
230                 headers: {
231                         Accept: "very wrong accept value"
232                 },
233                 beforeSend: function( xhr ) {
234                         xhr.setRequestHeader("Accept", "*/*");
235                 },
236                 success: function( data ) {
237                         strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" );
238                 }
239         });
241         ajaxTest( "jQuery.ajax() - contentType", 2, [
242                 {
243                         url: url("data/headers.php?keys=content-type"),
244                         contentType: "test",
245                         success: function( data ) {
246                                 strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" );
247                         }
248                 },
249                 {
250                         url: url("data/headers.php?keys=content-type"),
251                         contentType: false,
252                         success: function( data ) {
253                                 // Some server/interpreter combinations always supply a Content-Type to scripts
254                                 data = data || "content-type: \n";
255                                 strictEqual( data, "content-type: \n", "Test content-type is not set when options.contentType===false" );
256                         }
257                 }
258         ]);
260         ajaxTest( "jQuery.ajax() - protocol-less urls", 1, {
261                 url: "//somedomain.com",
262                 beforeSend: function( xhr, settings ) {
263                         equal( settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added." );
264                         return false;
265                 },
266                 error: true
267         });
269         ajaxTest( "jQuery.ajax() - hash", 3, [
270                 {
271                         url: "data/name.html#foo",
272                         beforeSend: function( xhr, settings ) {
273                                 equal( settings.url, "data/name.html", "Make sure that the URL is trimmed." );
274                                 return false;
275                         },
276                         error: true
277                 },
278                 {
279                         url: "data/name.html?abc#foo",
280                         beforeSend: function( xhr, settings ) {
281                                 equal( settings.url, "data/name.html?abc", "Make sure that the URL is trimmed." );
282                                 return false;
283                         },
284                         error: true
285                 },
286                 {
287                         url: "data/name.html?abc#foo",
288                         data: {
289                                 "test": 123
290                         },
291                         beforeSend: function( xhr, settings ) {
292                                 equal( settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed." );
293                                 return false;
294                         },
295                         error: true
296                 }
297         ]);
299         ajaxTest( "jQuery.ajax() - cross-domain detection", 7, function() {
300                 function request( url, title, crossDomainOrOptions ) {
301                         return jQuery.extend( {
302                                 dataType: "jsonp",
303                                 url: url,
304                                 beforeSend: function( _, s ) {
305                                         ok( crossDomainOrOptions === false ? !s.crossDomain : s.crossDomain, title );
306                                         return false;
307                                 },
308                                 error: true
309                         }, crossDomainOrOptions );
310                 }
312                 var loc = document.location,
313                         samePort = loc.port || ( loc.protocol === "http:" ? 80 : 443 ),
314                         otherPort = loc.port === 666 ? 667 : 666,
315                         otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
317                 return [
318                         request(
319                                 loc.protocol + "//" + loc.host + ":" + samePort,
320                                 "Test matching ports are not detected as cross-domain",
321                                 false
322                         ),
323                         request(
324                                 otherProtocol + "//" + loc.host,
325                                 "Test different protocols are detected as cross-domain"
326                         ),
327                         request(
328                                 "app:/path",
329                                 "Adobe AIR app:/ URL detected as cross-domain"
330                         ),
331                         request(
332                                 loc.protocol + "//example.invalid:" + ( loc.port || 80 ),
333                                 "Test different hostnames are detected as cross-domain"
334                         ),
335                         request(
336                                 loc.protocol + "//" + loc.hostname + ":" + otherPort,
337                                 "Test different ports are detected as cross-domain"
338                         ),
339                         request(
340                                 "about:blank",
341                                 "Test about:blank is detected as cross-domain"
342                         ),
343                         request(
344                                 loc.protocol + "//" + loc.host,
345                                 "Test forced crossDomain is detected as cross-domain",
346                                 {
347                                         crossDomain: true
348                                 }
349                         )
350                 ];
351         });
353         ajaxTest( "jQuery.ajax() - abort", 9, {
354                 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete"),
355                 url: url("data/name.php?wait=5"),
356                 beforeSend: function() {
357                         ok( true, "beforeSend" );
358                 },
359                 afterSend: function( xhr ) {
360                         strictEqual( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
361                         xhr.abort();
362                         strictEqual( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
363                 },
364                 error: true,
365                 complete: function() {
366                         ok( true, "complete" );
367                 }
368         });
370         ajaxTest( "jQuery.ajax() - events with context", 12, function() {
372                 var context = document.createElement("div");
374                 function event( e ) {
375                         equal( this, context, e.type );
376                 }
378                 function callback( msg ) {
379                         return function() {
380                                 equal( this, context, "context is preserved on callback " + msg );
381                         };
382                 }
384                 return {
385                         setup: function() {
386                                 jQuery( context ).appendTo("#foo")
387                                         .ajaxSend( event )
388                                         .ajaxComplete( event )
389                                         .ajaxError( event )
390                                         .ajaxSuccess( event );
391                         },
392                         requests: [{
393                                 url: url("data/name.html"),
394                                 context: context,
395                                 beforeSend: callback("beforeSend"),
396                                 success: callback("success"),
397                                 complete: callback("complete")
398                         }, {
399                                 url: url("data/404.html"),
400                                 context: context,
401                                 beforeSend: callback("beforeSend"),
402                                 error: callback("error"),
403                                 complete: callback("complete")
404                         }]
405                 };
406         });
408         ajaxTest( "jQuery.ajax() - events without context", 3, function() {
409                 function nocallback( msg ) {
410                         return function() {
411                                 equal( typeof this.url, "string", "context is settings on callback " + msg );
412                         };
413                 }
414                 return {
415                         url: url("data/404.html"),
416                         beforeSend: nocallback("beforeSend"),
417                         error: nocallback("error"),
418                         complete:  nocallback("complete")
419                 };
420         });
422         ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function() {
423                 var holder;
424                 return {
425                         url: url( "data/json.php" ),
426                         setup: function() {
427                                 holder = jQuery.event;
428                                 delete jQuery.event;
429                         },
430                         complete: function() {
431                                 ok( true, "Call can be made without jQuery.event" );
432                                 jQuery.event = holder;
433                         },
434                         success: true
435                 };
436         });
438         ajaxTest( "jQuery.ajax() - context modification", 1, {
439                 url: url("data/name.html"),
440                 context: {},
441                 beforeSend: function() {
442                         this.test = "foo";
443                 },
444                 afterSend: function() {
445                         strictEqual( this.context.test, "foo", "Make sure the original object is maintained." );
446                 },
447                 success: true
448         });
450         ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function() {
451                 var obj = {};
452                 return {
453                         setup: function() {
454                                 jQuery.ajaxSetup({
455                                         context: obj
456                                 });
457                                 strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." );
458                         },
459                         requests: [{
460                                 url: url("data/name.html"),
461                                 success: function() {
462                                         strictEqual( this, obj, "Make sure the original object is maintained." );
463                                 }
464                         }, {
465                                 url: url("data/name.html"),
466                                 context: {},
467                                 success: function() {
468                                         ok( this !== obj, "Make sure overriding context is possible." );
469                                 }
470                         }]
471                 };
472         });
474         ajaxTest( "jQuery.ajax() - disabled globals", 3, {
475                 setup: addGlobalEvents(""),
476                 global: false,
477                 url: url("data/name.html"),
478                 beforeSend: function() {
479                         ok( true, "beforeSend" );
480                 },
481                 success: function() {
482                         ok( true, "success" );
483                 },
484                 complete: function() {
485                         ok( true, "complete" );
486                 }
487         });
489         ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, {
490                 url: url("data/with_fries.xml"),
491                 dataType: "xml",
492                 success: function( resp ) {
493                         equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
494                         equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
495                         equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
496                 }
497         });
499         ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, {
500                 url: url("data/with_fries_over_jsonp.php"),
501                 dataType: "jsonp xml",
502                 success: function( resp ) {
503                         equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
504                         equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
505                         equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
506                 }
507         });
509         ajaxTest( "jQuery.ajax() - HEAD requests", 2, [
510                 {
511                         url: url("data/name.html"),
512                         type: "HEAD",
513                         success: function( data, status, xhr ) {
514                                 ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" );
515                         }
516                 },
517                 {
518                         url: url("data/name.html"),
519                         data: {
520                                 "whip_it": "good"
521                         },
522                         type: "HEAD",
523                         success: function( data, status, xhr ) {
524                                 ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response with data" );
525                         }
526                 }
527         ]);
529         ajaxTest( "jQuery.ajax() - beforeSend", 1, {
530                 url: url("data/name.html"),
531                 beforeSend: function() {
532                         this.check = true;
533                 },
534                 success: function() {
535                         ok( this.check, "check beforeSend was executed" );
536                 }
537         });
539         ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, {
540                 create: function() {
541                         return jQuery.ajax({
542                                 url: url("data/name.html"),
543                                 beforeSend: function( xhr ) {
544                                         ok( true, "beforeSend got called, canceling" );
545                                         xhr.abort();
546                                 },
547                                 success: function() {
548                                         ok( false, "request didn't get canceled" );
549                                 },
550                                 complete: function() {
551                                         ok( false, "request didn't get canceled" );
552                                 },
553                                 error: function() {
554                                         ok( false, "request didn't get canceled" );
555                                 }
556                         });
557                 },
558                 fail: function( _, reason ) {
559                         strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
560                 }
561         });
563         ajaxTest( "jQuery.ajax() - dataType html", 5, {
564                 setup: function() {
565                         Globals.register("testFoo");
566                         Globals.register("testBar");
567                 },
568                 dataType: "html",
569                 url: url("data/test.html"),
570                 success: function( data ) {
571                         ok( data.match( /^html text/ ), "Check content for datatype html" );
572                         jQuery("#ap").html( data );
573                         strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" );
574                         strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" );
575                 }
576         });
578         ajaxTest( "jQuery.ajax() - synchronous request", 1, {
579                 url: url("data/json_obj.js"),
580                 dataType: "text",
581                 async: false,
582                 success: true,
583                 afterSend: function( xhr ) {
584                         ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" );
585                 }
586         });
588         ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, {
589                 url: url("data/json_obj.js"),
590                 async: false,
591                 dataType: "text",
592                 success: true,
593                 afterSend: function( xhr ) {
594                         var result;
595                         xhr.done(function( data ) {
596                                 ok( true, "success callback executed" );
597                                 result = data;
598                         });
599                         ok( /^\{ "data"/.test( result ), "check returned text" );
600                 }
601         });
603         asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() {
604                 var target = "data/name.html",
605                         successCount = 0,
606                         errorCount = 0,
607                         errorEx = "",
608                         success = function() {
609                                 successCount++;
610                         };
611                 jQuery( document ).on( "ajaxError.passthru", function( e, xml ) {
612                         errorCount++;
613                         errorEx += ": " + xml.status;
614                 });
615                 jQuery( document ).one( "ajaxStop", function() {
616                         equal( successCount, 5, "Check all ajax calls successful" );
617                         equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" );
618                         jQuery( document ).off("ajaxError.passthru");
619                         start();
620                 });
621                 Globals.register("testBar");
623                 ok( jQuery.get( url(target), success ), "get" );
624                 ok( jQuery.post( url(target), success ), "post" );
625                 ok( jQuery.getScript( url("data/testbar.php"), success ), "script" );
626                 ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" );
627                 ok( jQuery.ajax({
628                         url: url( target ),
629                         success: success
630                 }), "generic" );
631         });
633         ajaxTest( "jQuery.ajax() - cache", 12, function() {
635                 var re = /_=(.*?)(&|$)/g;
637                 function request( url, title ) {
638                         return {
639                                 url: url,
640                                 cache: false,
641                                 beforeSend: function() {
642                                         var parameter, tmp;
643                                         while(( tmp = re.exec( this.url ) )) {
644                                                 strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" );
645                                                 parameter = tmp[ 1 ];
646                                                 notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" );
647                                         }
648                                         return false;
649                                 },
650                                 error: true
651                         };
652                 }
654                 return [
655                         request(
656                                 "data/text.php",
657                                 "no parameter"
658                         ),
659                         request(
660                                 "data/text.php?pizza=true",
661                                 "1 parameter"
662                         ),
663                         request(
664                                 "data/text.php?_=tobereplaced555",
665                                 "_= parameter"
666                         ),
667                         request(
668                                 "data/text.php?pizza=true&_=tobereplaced555",
669                                 "1 parameter and _="
670                         ),
671                         request(
672                                 "data/text.php?_=tobereplaced555&tv=false",
673                                 "_= and 1 parameter"
674                         ),
675                         request(
676                                 "data/text.php?name=David&_=tobereplaced555&washere=true",
677                                 "2 parameters surrounding _="
678                         )
679                 ];
680         });
682         jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
684                 ajaxTest( "jQuery.ajax() - JSONP - Query String (?n)" + label, 4, [
685                         {
686                                 url: "data/jsonp.php?callback=?",
687                                 dataType: "jsonp",
688                                 crossDomain: crossDomain,
689                                 success: function( data ) {
690                                         ok( data.data, "JSON results returned (GET, url callback)" );
691                                 }
692                         },
693                         {
694                                 url: "data/jsonp.php?callback=??",
695                                 dataType: "jsonp",
696                                 crossDomain: crossDomain,
697                                 success: function( data ) {
698                                         ok( data.data, "JSON results returned (GET, url context-free callback)" );
699                                 }
700                         },
701                         {
702                                 url: "data/jsonp.php/??",
703                                 dataType: "jsonp",
704                                 crossDomain: crossDomain,
705                                 success: function( data ) {
706                                         ok( data.data, "JSON results returned (GET, REST-like)" );
707                                 }
708                         },
709                         {
710                                 url: "data/jsonp.php/???json=1",
711                                 dataType: "jsonp",
712                                 crossDomain: crossDomain,
713                                 success: function( data ) {
714                                         strictEqual( jQuery.type( data ), "array", "JSON results returned (GET, REST-like with param)" );
715                                 }
716                         }
717                 ]);
719                 ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 9, {
720                         setup: function() {
721                                 Globals.register("functionToCleanUp");
722                                 Globals.register("XXX");
723                                 Globals.register("jsonpResults");
724                                 window["jsonpResults"] = function( data ) {
725                                         ok( data["data"], "JSON results returned (GET, custom callback function)" );
726                                 };
727                         },
728                         requests: [{
729                                 url: "data/jsonp.php",
730                                 dataType: "jsonp",
731                                 crossDomain: crossDomain,
732                                 jsonp: "callback",
733                                 success: function( data ) {
734                                         ok( data["data"], "JSON results returned (GET, data obj callback)" );
735                                 }
736                         }, {
737                                 url: "data/jsonp.php",
738                                 dataType: "jsonp",
739                                 crossDomain: crossDomain,
740                                 jsonpCallback: "jsonpResults",
741                                 success: function( data ) {
742                                         ok( data.data, "JSON results returned (GET, custom callback name)" );
743                                 }
744                         }, {
745                                 url: "data/jsonp.php",
746                                 dataType: "jsonp",
747                                 crossDomain: crossDomain,
748                                 jsonpCallback: "functionToCleanUp",
749                                 success: function( data ) {
750                                         ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" );
751                                         strictEqual( window["functionToCleanUp"], true, "Callback was removed (GET, custom callback name to be cleaned up)" );
752                                         var xhr;
753                                         jQuery.ajax({
754                                                 url: "data/jsonp.php",
755                                                 dataType: "jsonp",
756                                                 crossDomain: crossDomain,
757                                                 jsonpCallback: "functionToCleanUp",
758                                                 beforeSend: function( jqXHR ) {
759                                                         xhr = jqXHR;
760                                                         return false;
761                                                 }
762                                         });
763                                         xhr.fail(function() {
764                                                 ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
765                                                 strictEqual( window["functionToCleanUp"], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
766                                         });
767                                 }
768                         }, {
769                                 url: "data/jsonp.php?callback=XXX",
770                                 dataType: "jsonp",
771                                 jsonp: false,
772                                 jsonpCallback: "XXX",
773                                 crossDomain: crossDomain,
774                                 beforeSend: function() {
775                                         ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
776                                 },
777                                 success: function( data ) {
778                                         ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
779                                 }
780                         }]
781                 });
783                 ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, [
784                         {
785                                 url: "data/jsonp.php",
786                                 dataType: "jsonp",
787                                 crossDomain: crossDomain,
788                                 data: "callback=?",
789                                 success: function( data ) {
790                                         ok( data.data, "JSON results returned (GET, data callback)" );
791                                 }
792                         },
793                         {
794                                 url: "data/jsonp.php",
795                                 dataType: "jsonp",
796                                 crossDomain: crossDomain,
797                                 data: "callback=??",
798                                 success: function( data ) {
799                                         ok( data.data, "JSON results returned (GET, data context-free callback)" );
800                                 }
801                         }
802                 ]);
805                 ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, [
806                         {
807                                 type: "POST",
808                                 url: "data/jsonp.php",
809                                 dataType: "jsonp",
810                                 crossDomain: crossDomain,
811                                 success: function( data ) {
812                                         ok( data["data"], "JSON results returned (POST, no callback)" );
813                                 }
814                         },
815                         {
816                                 type: "POST",
817                                 url: "data/jsonp.php",
818                                 data: "callback=?",
819                                 dataType: "jsonp",
820                                 crossDomain: crossDomain,
821                                 success: function( data ) {
822                                         ok( data["data"], "JSON results returned (POST, data callback)" );
823                                 }
824                         },
825                         {
826                                 type: "POST",
827                                 url: "data/jsonp.php",
828                                 jsonp: "callback",
829                                 dataType: "jsonp",
830                                 crossDomain: crossDomain,
831                                 success: function( data ) {
832                                         ok( data["data"], "JSON results returned (POST, data obj callback)" );
833                                 }
834                         }
835                 ]);
837                 ajaxTest( "jQuery.ajax() - JSONP" + label, 3, [
838                         {
839                                 url: "data/jsonp.php",
840                                 dataType: "jsonp",
841                                 crossDomain: crossDomain,
842                                 success: function( data ) {
843                                         ok( data.data, "JSON results returned (GET, no callback)" );
844                                 }
845                         },
846                         {
847                                 create: function( options ) {
848                                         var request = jQuery.ajax( options ),
849                                                 promise = request.then(function( data ) {
850                                                         ok( data.data, "first request: JSON results returned (GET, no callback)" );
851                                                         request = jQuery.ajax( this ).done(function( data ) {
852                                                                 ok( data.data, "this re-used: JSON results returned (GET, no callback)" );
853                                                         });
854                                                         promise.abort = request.abort;
855                                                         return request;
856                                                 });
857                                         promise.abort = request.abort;
858                                         return promise;
859                                 },
860                                 url: "data/jsonp.php",
861                                 dataType: "jsonp",
862                                 crossDomain: crossDomain,
863                                 success: true
864                         }
865                 ]);
867         });
869         ajaxTest( "jQuery.ajax() - script, Remote", 2, {
870                 setup: function() {
871                         Globals.register("testBar");
872                 },
873                 url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php",
874                 dataType: "script",
875                 success: function() {
876                         strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
877                 }
878         });
880         ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, {
881                 setup: function() {
882                         Globals.register("testBar");
883                 },
884                 url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php",
885                 type: "POST",
886                 dataType: "script",
887                 success: function( data, status ) {
888                         strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" );
889                         strictEqual( status, "success", "Script results returned (POST, no callback)" );
890                 }
891         });
893         ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, {
894                 setup: function() {
895                         Globals.register("testBar");
896                 },
897                 url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/testbar.php",
898                 dataType: "script",
899                 success: function() {
900                         strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
901                 }
902         });
904         ajaxTest( "jQuery.ajax() - malformed JSON", 2, {
905                 url: "data/badjson.js",
906                 dataType: "json",
907                 error: function( xhr, msg, detailedMsg ) {
908                         strictEqual( msg, "parsererror", "A parse error occurred." );
909                         ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" );
910                 }
911         });
913         ajaxTest( "jQuery.ajax() - script by content-type", 2, [
914                 {
915                         url: "data/script.php",
916                         data: {
917                                 "header": "script"
918                         },
919                         success: true
920                 },
921                 {
922                         url: "data/script.php",
923                         data: {
924                                 "header": "ecma"
925                         },
926                         success: true
927                 }
928         ]);
930         ajaxTest( "jQuery.ajax() - JSON by content-type", 5, {
931                 url: "data/json.php",
932                 data: {
933                         "header": "json",
934                         "json": "array"
935                 },
936                 success: function( json ) {
937                         ok( json.length >= 2, "Check length" );
938                         strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
939                         strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
940                         strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
941                         strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
942                 }
943         });
945         ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, {
946                 url: url("data/json.php"),
947                 data: {
948                         "header": "json",
949                         "json": "array"
950                 },
951                 contents: {
952                         "json": false
953                 },
954                 success: function( text ) {
955                         strictEqual( typeof text, "string", "json wasn't auto-determined" );
956                         var json = jQuery.parseJSON( text );
957                         ok( json.length >= 2, "Check length");
958                         strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
959                         strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
960                         strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
961                         strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
962                 }
963         });
965         ajaxTest( "jQuery.ajax() - simple get", 1, {
966                 type: "GET",
967                 url: url("data/name.php?name=foo"),
968                 success: function( msg ) {
969                         strictEqual( msg, "bar", "Check for GET" );
970                 }
971         });
973         ajaxTest( "jQuery.ajax() - simple post", 1, {
974                 type: "POST",
975                 url: url("data/name.php"),
976                 data: "name=peter",
977                 success: function( msg ) {
978                         strictEqual( msg, "pan", "Check for POST" );
979                 }
980         });
982         ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, {
983                 url: "data/echoData.php",
984                 data: undefined,
985                 type: "post",
986                 success: function( result ) {
987                         strictEqual( result, "" );
988                 }
989         });
991         var ifModifiedNow = new Date();
993         jQuery.each(
994                 /* jQuery.each arguments start */
995                 {
996                         " (cache)": true,
997                         " (no cache)": false
998                 },
999                 function( label, cache ) {
1000                         var isOpera = !!window.opera;
1002                         asyncTest( "jQuery.ajax() - If-Modified-Since support" + label, 3, function() {
1003                                 var url = "data/if_modified_since.php?ts=" + ifModifiedNow++;
1005                                 jQuery.ajax({
1006                                         url: url,
1007                                         ifModified: true,
1008                                         cache: cache,
1009                                         success: function( data, status ) {
1010                                                 strictEqual( status, "success" );
1012                                                 jQuery.ajax({
1013                                                         url: url,
1014                                                         ifModified: true,
1015                                                         cache: cache,
1016                                                         success: function( data, status ) {
1017                                                                 if ( data === "FAIL" ) {
1018                                                                         ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')." );
1019                                                                         ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')." );
1020                                                                 } else {
1021                                                                         strictEqual( status, "notmodified" );
1022                                                                         ok( data == null, "response body should be empty" );
1023                                                                 }
1024                                                                 start();
1025                                                         },
1026                                                         error: function() {
1027                                                                 // Do this because opera simply refuses to implement 304 handling :(
1028                                                                 // A feature-driven way of detecting this would be appreciated
1029                                                                 // See: http://gist.github.com/599419
1030                                                                 ok( isOpera, "error" );
1031                                                                 ok( isOpera, "error" );
1032                                                                 start();
1033                                                         }
1034                                                 });
1035                                         },
1036                                         error: function() {
1037                                                 strictEqual( false, "error" );
1038                                                 // Do this because opera simply refuses to implement 304 handling :(
1039                                                 // A feature-driven way of detecting this would be appreciated
1040                                                 // See: http://gist.github.com/599419
1041                                                 ok( isOpera, "error" );
1042                                                 start();
1043                                         }
1044                                 });
1045                         });
1047                         asyncTest( "jQuery.ajax() - Etag support" + label, 3, function() {
1048                                 var url = "data/etag.php?ts=" + ifModifiedNow++;
1050                                 jQuery.ajax({
1051                                         url: url,
1052                                         ifModified: true,
1053                                         cache: cache,
1054                                         success: function( data, status ) {
1055                                                 strictEqual( status, "success" );
1057                                                 jQuery.ajax({
1058                                                         url: url,
1059                                                         ifModified: true,
1060                                                         cache: cache,
1061                                                         success: function( data, status ) {
1062                                                                 if ( data === "FAIL" ) {
1063                                                                         ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-None-Match')." );
1064                                                                         ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-None-Match')." );
1065                                                                 } else {
1066                                                                         strictEqual( status, "notmodified" );
1067                                                                         ok( data == null, "response body should be empty" );
1068                                                                 }
1069                                                                 start();
1070                                                         },
1071                                                         error: function() {
1072                                                                 // Do this because opera simply refuses to implement 304 handling :(
1073                                                                 // A feature-driven way of detecting this would be appreciated
1074                                                                 // See: http://gist.github.com/599419
1075                                                                 ok( isOpera, "error" );
1076                                                                 ok( isOpera, "error" );
1077                                                                 start();
1078                                                         }
1079                                                 });
1080                                         },
1081                                         error: function() {
1082                                                 // Do this because opera simply refuses to implement 304 handling :(
1083                                                 // A feature-driven way of detecting this would be appreciated
1084                                                 // See: http://gist.github.com/599419
1085                                                 ok( isOpera, "error" );
1086                                                 start();
1087                                         }
1088                                 });
1089                         });
1090                 }
1091                 /* jQuery.each arguments end */
1092         );
1094         ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, {
1095                 // see RFC 2606
1096                 url: "http://example.invalid",
1097                 error: function( xhr, _, e ) {
1098                         ok( true, "file not found: " + xhr.status + " => " + e );
1099                 }
1100         });
1102         ajaxTest( "jQuery.ajax() - failing cross-domain", 1, {
1103                 url: "http://" + externalHost,
1104                 error: function( xhr, _, e ) {
1105                         ok( true, "access denied: " + xhr.status + " => " + e );
1106                 }
1107         });
1109         ajaxTest( "jQuery.ajax() - atom+xml", 1, {
1110                 url: url("data/atom+xml.php"),
1111                 success: function() {
1112                         ok( true, "success" );
1113                 }
1114         });
1116         asyncTest( "jQuery.ajax() - statusText", 3, function() {
1117                 jQuery.ajax( url("data/statusText.php?status=200&text=Hello") ).done(function( _, statusText, jqXHR ) {
1118                         strictEqual( statusText, "success", "callback status text ok for success" );
1119                         ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" );
1120                         jQuery.ajax( url("data/statusText.php?status=404&text=World") ).fail(function( jqXHR, statusText ) {
1121                                 strictEqual( statusText, "error", "callback status text ok for error" );
1122                                 // ok( jqXHR.statusText === "World" || jQuery.browser.safari && jqXHR.statusText === "Not Found", "jqXHR status text ok for error (" + jqXHR.statusText + ")" );
1123                                 start();
1124                         });
1125                 });
1126         });
1128         asyncTest( "jQuery.ajax() - statusCode", 20, function() {
1130                 var count = 12;
1132                 function countComplete() {
1133                         if ( ! --count ) {
1134                                 start();
1135                         }
1136                 }
1138                 function createStatusCodes( name, isSuccess ) {
1139                         name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
1140                         return {
1141                                 200: function() {
1142                                         ok( isSuccess, name );
1143                                 },
1144                                 404: function() {
1145                                         ok( !isSuccess, name );
1146                                 }
1147                         };
1148                 }
1150                 jQuery.each(
1151                         /* jQuery.each arguments start */
1152                         {
1153                                 "data/name.html": true,
1154                                 "data/someFileThatDoesNotExist.html": false
1155                         },
1156                         function( uri, isSuccess ) {
1158                                 jQuery.ajax( url(uri), {
1159                                         statusCode: createStatusCodes( "in options", isSuccess ),
1160                                         complete: countComplete
1161                                 });
1163                                 jQuery.ajax( url(uri), {
1164                                         complete: countComplete
1165                                 }).statusCode( createStatusCodes("immediately with method", isSuccess) );
1167                                 jQuery.ajax( url(uri), {
1168                                         complete: function( jqXHR ) {
1169                                                 jqXHR.statusCode( createStatusCodes("on complete", isSuccess) );
1170                                                 countComplete();
1171                                         }
1172                                 });
1174                                 jQuery.ajax( url(uri), {
1175                                         complete: function( jqXHR ) {
1176                                                 setTimeout(function() {
1177                                                         jqXHR.statusCode( createStatusCodes("very late binding", isSuccess) );
1178                                                         countComplete();
1179                                                 }, 100 );
1180                                         }
1181                                 });
1183                                 jQuery.ajax( url(uri), {
1184                                         statusCode: createStatusCodes( "all (options)", isSuccess ),
1185                                         complete: function( jqXHR ) {
1186                                                 jqXHR.statusCode( createStatusCodes("all (on complete)", isSuccess) );
1187                                                 setTimeout(function() {
1188                                                         jqXHR.statusCode( createStatusCodes("all (very late binding)", isSuccess) );
1189                                                         countComplete();
1190                                                 }, 100 );
1191                                         }
1192                                 }).statusCode( createStatusCodes("all (immediately with method)", isSuccess) );
1194                                 var testString = "";
1196                                 jQuery.ajax( url(uri), {
1197                                         success: function( a, b, jqXHR ) {
1198                                                 ok( isSuccess, "success" );
1199                                                 var statusCode = {};
1200                                                 statusCode[ jqXHR.status ] = function() {
1201                                                         testString += "B";
1202                                                 };
1203                                                 jqXHR.statusCode( statusCode );
1204                                                 testString += "A";
1205                                         },
1206                                         error: function( jqXHR ) {
1207                                                 ok( !isSuccess, "error" );
1208                                                 var statusCode = {};
1209                                                 statusCode[ jqXHR.status ] = function() {
1210                                                         testString += "B";
1211                                                 };
1212                                                 jqXHR.statusCode( statusCode );
1213                                                 testString += "A";
1214                                         },
1215                                         complete: function() {
1216                                                 strictEqual(
1217                                                         testString,
1218                                                         "AB",
1219                                                         "Test statusCode callbacks are ordered like " + ( isSuccess ? "success" :  "error" ) + " callbacks"
1220                                                 );
1221                                                 countComplete();
1222                                         }
1223                                 });
1225                         }
1226                         /* jQuery.each arguments end*/
1227                 );
1228         });
1230         ajaxTest( "jQuery.ajax() - transitive conversions", 8, [
1231                 {
1232                         url: url("data/json.php"),
1233                         converters: {
1234                                 "json myJson": function( data ) {
1235                                         ok( true, "converter called" );
1236                                         return data;
1237                                 }
1238                         },
1239                         dataType: "myJson",
1240                         success: function() {
1241                                 ok( true, "Transitive conversion worked" );
1242                                 strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text" );
1243                                 strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType" );
1244                         }
1245                 },
1246                 {
1247                         url: url("data/json.php"),
1248                         converters: {
1249                                 "json myJson": function( data ) {
1250                                         ok( true, "converter called (*)" );
1251                                         return data;
1252                                 }
1253                         },
1254                         contents: false, /* headers are wrong so we ignore them */
1255                         dataType: "* myJson",
1256                         success: function() {
1257                                 ok( true, "Transitive conversion worked (*)" );
1258                                 strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text (*)" );
1259                                 strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType (*)" );
1260                         }
1261                 }
1262         ]);
1264         ajaxTest( "jQuery.ajax() - overrideMimeType", 2, [
1265                 {
1266                         url: url("data/json.php"),
1267                         beforeSend: function( xhr ) {
1268                                 xhr.overrideMimeType( "application/json" );
1269                         },
1270                         success: function( json ) {
1271                                 ok( json.data, "Mimetype overridden using beforeSend" );
1272                         }
1273                 },
1274                 {
1275                         url: url("data/json.php"),
1276                         mimeType: "application/json",
1277                         success: function( json ) {
1278                                 ok( json.data, "Mimetype overridden using mimeType option" );
1279                         }
1280                 }
1281         ]);
1283         ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, {
1284                 url: url("data/echoData.php"),
1285                 error: function( _, __, error ) {
1286                         equal( typeof error === "object", true,  "Didn't get back error object for empty json response" );
1287                 },
1288                 dataType: "json"
1289         });
1291         ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, {
1292                 create: function() {
1293                         return jQuery.ajax({
1294                                 url: url("data/name.html"),
1295                                 beforeSend: function() {
1296                                         ok( true, "beforeSend got called, canceling" );
1297                                         return false;
1298                                 },
1299                                 success: function() {
1300                                         ok( false, "request didn't get canceled" );
1301                                 },
1302                                 complete: function() {
1303                                         ok( false, "request didn't get canceled" );
1304                                 },
1305                                 error: function() {
1306                                         ok( false, "request didn't get canceled" );
1307                                 }
1308                         });
1309                 },
1310                 fail: function( _, reason ) {
1311                         strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
1312                 }
1313         });
1315         ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, {
1316                 url: "data/echoQuery.php",
1317                 data: {
1318                         key: function() {
1319                                 return "value";
1320                         }
1321                 },
1322                 success: function( result ) {
1323                         strictEqual( result, "key=value" );
1324                 }
1325         });
1327         test( "#7531 - jQuery.ajax() - Location object as url", 1, function () {
1328                 var xhr,
1329                         success = false;
1330                 try {
1331                         xhr = jQuery.ajax({
1332                                 url: window.location
1333                         });
1334                         success = true;
1335                         xhr.abort();
1336                 } catch (e) {
1338                 }
1339                 ok( success, "document.location did not generate exception" );
1340         });
1342         jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
1343                 ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, {
1344                         url: "data/jsonp.php",
1345                         dataType: "jsonp",
1346                         crossDomain: crossDomain,
1347                         beforeSend: function() {
1348                                 strictEqual( this.cache, false, "cache must be false on JSON request" );
1349                                 return false;
1350                         },
1351                         error: true
1352                 });
1353         });
1355         ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, [
1356                 {
1357                         create: function() {
1358                                 return jQuery.ajax();
1359                         },
1360                         done: function() {
1361                                 ok( true, "With no arguments" );
1362                         }
1363                 },
1364                 {
1365                         create: function() {
1366                                 return jQuery.ajax("data/name.html");
1367                         },
1368                         done: function() {
1369                                 ok( true, "With only string URL argument" );
1370                         }
1371                 },
1372                 {
1373                         create: function() {
1374                                 return jQuery.ajax( "data/name.html", {});
1375                         },
1376                         done: function() {
1377                                 ok( true, "With string URL param and map" );
1378                         }
1379                 },
1380                 {
1381                         create: function( options ) {
1382                                 return jQuery.ajax( options );
1383                         },
1384                         url: "data/name.html",
1385                         success: function() {
1386                                 ok( true, "With only map" );
1387                         }
1388                 }
1389         ]);
1391         jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
1392                 ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 2, {
1393                         url: "data/jsonp.php",
1394                         dataType: "jsonp",
1395                         crossDomain: crossDomain,
1396                         beforeSend: function( jqXHR, s ) {
1397                                 s.callback = s.jsonpCallback;
1398                         },
1399                         success: function() {
1400                                 var previous = this;
1401                                 strictEqual( previous.jsonpCallback, undefined, "jsonpCallback option is set back to default in callbacks" );
1402                                 jQuery.ajax({
1403                                         url: "data/jsonp.php",
1404                                         dataType: "jsonp",
1405                                         crossDomain: crossDomain,
1406                                         beforeSend: function() {
1407                                                 strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" );
1408                                                 return false;
1409                                         }
1410                                 });
1411                         }
1412                 });
1413         });
1415         test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", 2, function () {
1416                 var success = false,
1417                         context = {};
1418                 context.field = context;
1419                 try {
1420                         jQuery.ajax( "non-existing", {
1421                                 context: context,
1422                                 beforeSend: function() {
1423                                         ok( this === context, "context was not deep extended" );
1424                                         return false;
1425                                 }
1426                         });
1427                         success = true;
1428                 } catch ( e ) {
1429                         console.log( e );
1430                 }
1431                 ok( success, "context with circular reference did not generate an exception" );
1432         });
1434         jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) {
1436                 function request( url, test ) {
1437                         return {
1438                                 create: function() {
1439                                         return jQuery.ajax( inSetting ? { url: url } : url );
1440                                 },
1441                                 done: function() {
1442                                         ok( true, ( test || url ) + " " + title );
1443                                 }
1444                         };
1445                 }
1447                 ajaxTest( "#10093 - jQuery.ajax() - falsy url " + title, 4, [
1448                         request( "", "empty string" ),
1449                         request( false ),
1450                         request( null ),
1451                         request( undefined )
1452                 ]);
1454         });
1456         ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, {
1457                 url: url("data/errorWithJSON.php"),
1458                 dataFilter: function( string ) {
1459                         ok( false, "dataFilter called" );
1460                         return string;
1461                 },
1462                 error: function( jqXHR ) {
1463                         strictEqual( jqXHR.responseText, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" );
1464                         deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" );
1465                 }
1466         });
1468         ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, {
1469                 url: url("data/1x1.jpg"),
1470                 success: function( data ) {
1471                         ok( data === undefined || /JFIF/.test( data ), "success callback reached" );
1472                 }
1473         });
1475         asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function() {
1476                 var onerror = window.onerror;
1477                 window.onerror = function() {
1478                         ok( true, "Exception thrown" );
1479                         window.onerror = onerror;
1480                         start();
1481                 };
1482                 jQuery.ajax({
1483                         url: "data/badjson.js",
1484                         dataType: "script",
1485                         "throws": true
1486                 });
1487         });
1489         jQuery.each( [ "method", "type" ], function( _, globalOption ) {
1491                 function request( option ) {
1492                         var options = {
1493                                         url: url("data/echoData.php"),
1494                                         data: "hello",
1495                                         success: function( msg ) {
1496                                                 strictEqual( msg, "hello", "Check for POST (no override)" );
1497                                         }
1498                                 };
1499                         if ( option ) {
1500                                 options[ option ] = "GET";
1501                                 options.success = function( msg ) {
1502                                         strictEqual( msg, "", "Check for no POST (overriding with " + option + ")" );
1503                                 };
1504                         }
1505                         return options;
1506                 }
1508                 ajaxTest( "#12004 - jQuery.ajax() - method is an alias of type - " + globalOption + " set globally", 3, {
1509                         setup: function() {
1510                                 var options = {};
1511                                 options[ globalOption ] = "POST";
1512                                 jQuery.ajaxSetup( options );
1513                         },
1514                         requests: [
1515                                 request("type"),
1516                                 request("method"),
1517                                 request()
1518                         ]
1519                 });
1521         });
1523         ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, {
1524                 url: "data/dashboard.xml",
1525                 dataType: "xml",
1526                 success: function( ajaxXML ) {
1527                         var parsedXML = jQuery( jQuery.parseXML("<tab title=\"Added\">blibli</tab>") ).find("tab");
1528                         ajaxXML = jQuery( ajaxXML );
1529                         try {
1530                                 // Android 2.3 doesn't automatically adopt nodes from foreign documents.
1531                                 // (see the comment in test/manipulation.js)
1532                                 // Support: Android 2.3
1533                                 if ( /android 2\.3/i.test( navigator.userAgent ) ) {
1534                                         parsedXML = jQuery( ajaxXML[ 0 ].adoptNode( parsedXML[ 0 ] ) );
1535                                 }
1536                                 ajaxXML.find("infowindowtab").append( parsedXML );
1537                         } catch( e ) {
1538                                 strictEqual( e, undefined, "error" );
1539                                 return;
1540                         }
1541                         strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" );
1542                 }
1543         });
1545         ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, {
1546                 url: "data/nocontent.php",
1547                 dataType: "testing",
1548                 converters: {
1549                         "* testing": function() {
1550                                 throw "converter was called";
1551                         }
1552                 },
1553                 success: function( data, status, jqXHR ) {
1554                         strictEqual( jqXHR.status, 204, "status code is 204" );
1555                         strictEqual( status, "nocontent", "status text is 'nocontent'" );
1556                         strictEqual( data, undefined, "data is undefined" );
1557                 },
1558                 error: function( _, status, error ) {
1559                         ok( false, "error" );
1560                         strictEqual( status, "parsererror", "Parser Error" );
1561                         strictEqual( error, "converter was called", "Converter was called" );
1562                 }
1563         });
1565         ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, {
1566                 url: url("data/with_fries.xml"),
1567                 dataType: "xml",
1568                 success: function( resp, _, jqXHR ) {
1569                         notStrictEqual( resp, undefined, "XML document exists" );
1570                         ok( "responseXML" in jqXHR, "jqXHR.responseXML exists" );
1571                         strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" );
1572                 }
1573         });
1575         ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, {
1576                 url: "data/json.php",
1577                 method: "HEAD",
1578                 data: {
1579                         header: "yes"
1580                 },
1581                 converters: {
1582                         "text json": function() {
1583                                 throw "converter was called";
1584                         }
1585                 },
1586                 success: function( data, status ) {
1587                         ok( true, "success" );
1588                         strictEqual( status, "nocontent", "data is undefined" );
1589                         strictEqual( data, undefined, "data is undefined" );
1590                 },
1591                 error: function( _, status, error ) {
1592                         ok( false, "error" );
1593                         strictEqual( status, "parsererror", "Parser Error" );
1594                         strictEqual( error, "converter was called", "Converter was called" );
1595                 }
1596         } );
1598         ajaxTest( "#13240 - jQuery.ajax() - support non-RFC2616 methods", 1, {
1599                 url: "data/echoQuery.php",
1600                 method: "PATCH",
1601                 success: function() {
1602                         ok( true, "success" );
1603                 },
1604                 error: function() {
1605                         ok( false, "error" );
1606                 }
1607         });
1609         testIframeWithCallback( "#14379 - jQuery.ajax() on unload", "ajax/onunload.html", function( status ) {
1610                 expect( 1 );
1611                 strictEqual( status, "success", "Request completed" );
1612         });
1614 //----------- jQuery.ajaxPrefilter()
1616         ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, {
1617                 dataType: "prefix",
1618                 setup: function() {
1619                         // Ensure prefix does not throw an error
1620                         jQuery.ajaxPrefilter("+prefix", function( options, _, jqXHR ) {
1621                                 if ( options.abortInPrefilter ) {
1622                                         jqXHR.abort();
1623                                 }
1624                         });
1625                 },
1626                 abortInPrefilter: true,
1627                 error: function() {
1628                         ok( false, "error callback called" );
1629                 },
1630                 fail: function( _, reason ) {
1631                         strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" );
1632                 }
1633         });
1635 //----------- jQuery.ajaxSetup()
1637         asyncTest( "jQuery.ajaxSetup()", 1, function() {
1638                 jQuery.ajaxSetup({
1639                         url: url("data/name.php?name=foo"),
1640                         success: function( msg ) {
1641                                 strictEqual( msg, "bar", "Check for GET" );
1642                                 start();
1643                         }
1644                 });
1645                 jQuery.ajax();
1646         });
1648         asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function() {
1649                 var passed = 0,
1650                         pass = function() {
1651                                 ok( passed++ < 2, "Error callback executed" );
1652                                 if ( passed === 2 ) {
1653                                         jQuery( document ).off("ajaxError.setupTest");
1654                                         start();
1655                                 }
1656                         },
1657                         fail = function( a, b ) {
1658                                 ok( false, "Check for timeout failed " + a + " " + b );
1659                                 start();
1660                         };
1662                 jQuery( document ).on( "ajaxError.setupTest", pass );
1664                 jQuery.ajaxSetup({
1665                         timeout: 1000
1666                 });
1668                 jQuery.ajax({
1669                         type: "GET",
1670                         url: url("data/name.php?wait=5"),
1671                         error: pass,
1672                         success: fail
1673                 });
1674         });
1676         asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function() {
1677                 jQuery.ajaxSetup({
1678                         timeout: 50
1679                 });
1680                 jQuery.ajax({
1681                         type: "GET",
1682                         timeout: 15000,
1683                         url: url("data/name.php?wait=1"),
1684                         error: function() {
1685                                 ok( false, "Check for local timeout failed" );
1686                                 start();
1687                         },
1688                         success: function() {
1689                                 ok( true, "Check for local timeout" );
1690                                 start();
1691                         }
1692                 });
1693         });
1695 //----------- jQuery.domManip()
1697         test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", 1, function() {
1698                 jQuery.ajaxSetup({
1699                         type: "POST"
1700                 });
1702                 jQuery( document ).on( "ajaxStart ajaxStop", function() {
1703                         ok( false, "Global event triggered" );
1704                 });
1706                 jQuery("#qunit-fixture").append("<script src='data/evalScript.php'></script>");
1708                 jQuery( document ).off("ajaxStart ajaxStop");
1709         });
1711         asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() {
1712                 jQuery("#qunit-fixture").load( "data/cleanScript.html", start );
1713         });
1715 //----------- jQuery.get()
1717         asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function() {
1718                 jQuery.get( url("data/dashboard.xml"), function( xml ) {
1719                         var content = [];
1720                         jQuery( "tab", xml ).each(function() {
1721                                 content.push( jQuery( this ).text() );
1722                         });
1723                         strictEqual( content[ 0 ], "blabla", "Check first tab" );
1724                         strictEqual( content[ 1 ], "blublu", "Check second tab" );
1725                         start();
1726                 });
1727         });
1729         asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function() {
1730                 jQuery.ajaxSetup({
1731                         data: "helloworld"
1732                 });
1733                 jQuery.get( url("data/echoQuery.php"), function( data ) {
1734                         ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" );
1735                         start();
1736                 });
1737         });
1739 //----------- jQuery.getJSON()
1741         asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function() {
1742                 jQuery.getJSON(
1743                         url("data/json.php"),
1744                         {
1745                                 "json": "array"
1746                         },
1747                         function( json ) {
1748                                 ok( json.length >= 2, "Check length" );
1749                                 strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
1750                                 strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
1751                                 strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
1752                                 strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
1753                                 start();
1754                         }
1755                 );
1756         });
1758         asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function() {
1759                 jQuery.getJSON( url("data/json.php"), function( json ) {
1760                         if ( json && json["data"] ) {
1761                                 strictEqual( json["data"]["lang"], "en", "Check JSON: lang" );
1762                                 strictEqual( json["data"].length, 25, "Check JSON: length" );
1763                                 start();
1764                         }
1765                 });
1766         });
1768         asyncTest( "jQuery.getJSON() - Using Native JSON", 2, function() {
1769                 var restore = "JSON" in window,
1770                         old = window.JSON;
1771                 if ( !restore ) {
1772                         Globals.register("JSON");
1773                 }
1774                 window.JSON = {
1775                         parse: function() {
1776                                 ok( true, "Verifying that parse method was run" );
1777                                 window.JSON = old;
1778                                 return true;
1779                         }
1780                 };
1781                 jQuery.getJSON( url("data/json.php"), function( json ) {
1782                         strictEqual( json, true, "Verifying return value" );
1783                         start();
1784                 });
1785         });
1787         asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function() {
1788                 jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) {
1789                         strictEqual( json.data.lang, "en", "Check JSON: lang" );
1790                         strictEqual( json.data.length, 25, "Check JSON: length" );
1791                         start();
1792                 });
1793         });
1795 //----------- jQuery.getScript()
1797         asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() {
1798                 Globals.register("testBar");
1799                 jQuery.getScript( url("data/testbar.php"), function() {
1800                         strictEqual( window["testBar"], "bar", "Check if script was evaluated" );
1801                         start();
1802                 });
1803         });
1805         asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() {
1806                 Globals.register("testBar");
1807                 jQuery.getScript( url("data/testbar.php") ).done( start );
1808         });
1810         asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function() {
1811                 Globals.register("testBar");
1812                 jQuery.getScript( url("data/testbar.php"), function( data, _, jqXHR ) {
1813                         strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" );
1814                         start();
1815                 });
1816         });
1818 //----------- jQuery.fn.load()
1820         // check if load can be called with only url
1821         asyncTest( "jQuery.fn.load( String )", 2, function() {
1822                 jQuery.ajaxSetup({
1823                         beforeSend: function() {
1824                                 strictEqual( this.type, "GET", "no data means GET request" );
1825                         }
1826                 });
1827                 jQuery("#first").load( "data/name.html", start );
1828         });
1830         asyncTest( "jQuery.fn.load() - 404 error callbacks", 6, function() {
1831                 addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError")();
1832                 jQuery( document ).ajaxStop( start );
1833                 jQuery("<div/>").load( "data/404.html", function() {
1834                         ok( true, "complete" );
1835                 });
1836         });
1838         // check if load can be called with url and null data
1839         asyncTest( "jQuery.fn.load( String, null )", 2, function() {
1840                 jQuery.ajaxSetup({
1841                         beforeSend: function() {
1842                                 strictEqual( this.type, "GET", "no data means GET request" );
1843                         }
1844                 });
1845                 jQuery("#first").load( "data/name.html", null, start );
1846         });
1848         // check if load can be called with url and undefined data
1849         asyncTest( "jQuery.fn.load( String, undefined )", 2, function() {
1850                 jQuery.ajaxSetup({
1851                         beforeSend: function() {
1852                                 strictEqual( this.type, "GET", "no data means GET request" );
1853                         }
1854                 });
1855                 jQuery("#first").load( "data/name.html", undefined, start );
1856         });
1858         // check if load can be called with only url
1859         asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function() {
1860                 jQuery("#first").load( "data/test3.html div.user", function() {
1861                         strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" );
1862                         start();
1863                 });
1864         });
1866         // Selector should be trimmed to avoid leading spaces (#14773)
1867         asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function() {
1868                 jQuery("#first").load( "data/test3.html   #superuser ", function() {
1869                         strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" );
1870                         start();
1871                 });
1872         });
1874         asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() {
1875                 jQuery("#first").load( url("data/name.html"), function() {
1876                         ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );
1877                         start();
1878                 });
1879         });
1881         asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function() {
1882                 var verifyEvaluation = function() {
1883                         strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" );
1884                         strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
1885                         start();
1886                 };
1888                 Globals.register("testFoo");
1889                 Globals.register("testBar");
1891                 jQuery("#first").load( url("data/test.html"), function() {
1892                         ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" );
1893                         strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" );
1894                         strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
1895                         setTimeout( verifyEvaluation, 600 );
1896                 });
1897         });
1899         asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function() {
1900                 Globals.register("testFoo");
1902                 jQuery("#first").load( url("data/test2.html"), function() {
1903                         strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
1904                         strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
1905                         start();
1906                 });
1907         });
1909         asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function() {
1910                 jQuery.ajaxSetup({
1911                         dataFilter: function() {
1912                                 return "Hello World";
1913                         }
1914                 });
1915                 jQuery("<div/>").load( url("data/name.html"), function( responseText ) {
1916                         strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
1917                         strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
1918                         start();
1919                 });
1920         });
1922         asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function() {
1923                 jQuery("<div />").load( url("data/params_html.php"), {
1924                         "foo": 3,
1925                         "bar": "ok"
1926                 }, function() {
1927                         var $post = jQuery( this ).find("#post");
1928                         strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" );
1929                         strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" );
1930                         start();
1931                 });
1932         });
1934         asyncTest( "jQuery.fn.load( String, String, Function )", 2, function() {
1935                 jQuery("<div />").load( url("data/params_html.php"), "foo=3&bar=ok", function() {
1936                         var $get = jQuery( this ).find("#get");
1937                         strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" );
1938                         strictEqual( $get.find("#bar").text(), "ok", "Check if a   of data is passed correctly" );
1939                         start();
1940                 });
1941         });
1943         asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() {
1944                 var completeArgs = {};
1946                 jQuery.ajaxSetup({
1947                         success: function( _, status, jqXHR ) {
1948                                 completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
1949                         },
1950                         error: function( jqXHR, status ) {
1951                                 completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
1952                         }
1953                 });
1955                 jQuery.when.apply(
1956                         jQuery,
1957                         jQuery.map([
1958                                 {
1959                                         type: "success",
1960                                         url: "data/echoQuery.php?arg=pop"
1961                                 },
1962                                 {
1963                                         type: "error",
1964                                         url: "data/404.php"
1965                                 }
1966                         ],
1967                         function( options ) {
1968                                 return jQuery.Deferred(function( defer ) {
1969                                         jQuery("#foo").load( options.url, function() {
1970                                                 var args = arguments;
1971                                                 strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" );
1972                                                 jQuery.each( completeArgs[ options.url ], function( i, value ) {
1973                                                         strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" );
1974                                                 });
1975                                                 defer.resolve();
1976                                         });
1977                                 });
1978                         })
1979                 ).always( start );
1980         });
1982         asyncTest( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function() {
1983                 jQuery.ajaxSetup({
1984                         dataType: "json"
1985                 });
1986                 jQuery( document ).ajaxComplete(function( e, xml, s ) {
1987                         strictEqual( s.dataType, "html", "Verify the load() dataType was html" );
1988                         jQuery( document ).off("ajaxComplete");
1989                         start();
1990                 });
1991                 jQuery("#first").load("data/test3.html");
1992         });
1994         asyncTest( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function() {
1995                 var data = {
1996                         "baz": 1
1997                 };
1998                 jQuery.ajaxSetup({
1999                         data: {
2000                                 "foo": "bar"
2001                         }
2002                 });
2003                 jQuery("#foo").load( "data/echoQuery.php", data );
2004                 jQuery( document ).ajaxComplete(function( event, jqXHR, options ) {
2005                         ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" );
2006                         start();
2007                 });
2008         });
2010 //----------- jQuery.post()
2012         asyncTest( "jQuery.post() - data", 3, function() {
2013                 jQuery.when(
2014                         jQuery.post(
2015                                 url("data/name.php"),
2016                                 {
2017                                         xml: "5-2",
2018                                         length: 3
2019                                 },
2020                                 function( xml ) {
2021                                         jQuery( "math", xml ).each(function() {
2022                                                 strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2023                                                 strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2024                                         });
2025                                 }
2026                         ),
2027                         jQuery.ajax({
2028                                 url: url("data/echoData.php"),
2029                                 type: "POST",
2030                                 data: {
2031                                         "test": {
2032                                                 "length": 7,
2033                                                 "foo": "bar"
2034                                         }
2035                                 },
2036                                 success: function( data ) {
2037                                         strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" );
2038                                 }
2039                         })
2040                 ).always(function() {
2041                         start();
2042                 });
2043         });
2045         asyncTest( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function() {
2046                 jQuery.when(
2047                         jQuery.post(
2048                                 url("data/name.php"),
2049                                 {
2050                                         "xml": "5-2"
2051                                 },
2052                                 function( xml ) {
2053                                         jQuery( "math", xml ).each(function() {
2054                                                 strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2055                                                 strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2056                                         });
2057                                 }
2058                         ),
2059                         jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) {
2060                                 jQuery( "math", xml ).each(function() {
2061                                         strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2062                                         strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2063                                 });
2064                         })
2065                 ).always(function() {
2066                         start();
2067                 });
2068         });
2070 //----------- jQuery.active
2072         test( "jQuery.active", 1, function() {
2073                 ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );
2074         });
2076 })();