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