Grouped up the test
[jquery.git] / test / unit / ajax.js
1 module("ajax", { teardown: moduleTeardown });
2
3 // Safari 3 randomly crashes when running these tests,
4 // but only in the full suite - you can run just the Ajax
5 // tests and they'll pass
6 //if ( !jQuery.browser.safari ) {
7
8 if ( !isLocal ) {
9
10 test("jQuery.ajax() - success callbacks", function() {
11         expect( 8 );
12
13         jQuery.ajaxSetup({ timeout: 0 });
14
15         stop();
16
17         jQuery('#foo').ajaxStart(function(){
18                 ok( true, "ajaxStart" );
19         }).ajaxStop(function(){
20                 ok( true, "ajaxStop" );
21                 start();
22         }).ajaxSend(function(){
23                 ok( true, "ajaxSend" );
24         }).ajaxComplete(function(){
25                 ok( true, "ajaxComplete" );
26         }).ajaxError(function(){
27                 ok( false, "ajaxError" );
28         }).ajaxSuccess(function(){
29                 ok( true, "ajaxSuccess" );
30         });
31
32         jQuery.ajax({
33                 url: url("data/name.html"),
34                 beforeSend: function(){ ok(true, "beforeSend"); },
35                 success: function(){ ok(true, "success"); },
36                 error: function(){ ok(false, "error"); },
37                 complete: function(){ ok(true, "complete"); }
38         });
39 });
40
41 test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
42         expect( 8 );
43
44         jQuery.ajaxSetup({ timeout: 0 });
45
46         stop();
47
48         setTimeout(function(){
49                 jQuery('#foo').ajaxStart(function(){
50                         ok( true, "ajaxStart" );
51                 }).ajaxStop(function(){
52                         ok( true, "ajaxStop" );
53                         start();
54                 }).ajaxSend(function(){
55                         ok( true, "ajaxSend" );
56                 }).ajaxComplete(function(){
57                         ok( true, "ajaxComplete" );
58                 }).ajaxError(function(){
59                         ok( false, "ajaxError" );
60                 }).ajaxSuccess(function(){
61                         ok( true, "ajaxSuccess" );
62                 });
63
64                 jQuery.ajax( url("data/name.html") , {
65                         beforeSend: function(){ ok(true, "beforeSend"); },
66                         success: function(){ ok(true, "success"); },
67                         error: function(){ ok(false, "error"); },
68                         complete: function(){ ok(true, "complete"); }
69                 });
70         }, 13);
71 });
72
73 test("jQuery.ajax() - success callbacks (late binding)", function() {
74         expect( 8 );
75
76         jQuery.ajaxSetup({ timeout: 0 });
77
78         stop();
79
80         setTimeout(function(){
81                 jQuery('#foo').ajaxStart(function(){
82                         ok( true, "ajaxStart" );
83                 }).ajaxStop(function(){
84                         ok( true, "ajaxStop" );
85                         start();
86                 }).ajaxSend(function(){
87                         ok( true, "ajaxSend" );
88                 }).ajaxComplete(function(){
89                         ok( true, "ajaxComplete" );
90                 }).ajaxError(function(){
91                         ok( false, "ajaxError" );
92                 }).ajaxSuccess(function(){
93                         ok( true, "ajaxSuccess" );
94                 });
95
96                 jQuery.ajax({
97                         url: url("data/name.html"),
98                         beforeSend: function(){ ok(true, "beforeSend"); }
99                 })
100                         .complete(function(){ ok(true, "complete"); })
101                         .success(function(){ ok(true, "success"); })
102                         .error(function(){ ok(false, "error"); });
103         }, 13);
104 });
105
106 test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
107         expect( 8 );
108
109         jQuery.ajaxSetup({ timeout: 0 });
110
111         stop();
112
113         setTimeout(function(){
114                 jQuery('#foo').ajaxStart(function(){
115                         ok( true, "ajaxStart" );
116                 }).ajaxStop(function(){
117                         ok( true, "ajaxStop" );
118                 }).ajaxSend(function(){
119                         ok( true, "ajaxSend" );
120                 }).ajaxComplete(function(){
121                         ok( true, "ajaxComplete" );
122                 }).ajaxError(function(){
123                         ok( false, "ajaxError" );
124                 }).ajaxSuccess(function(){
125                         ok( true, "ajaxSuccess" );
126                 });
127
128                 jQuery.ajax({
129                         url: url("data/name.html"),
130                         beforeSend: function(){ ok(true, "beforeSend"); },
131                         complete: function(xhr) {
132                                 xhr
133                                 .complete(function(){ ok(true, "complete"); })
134                                 .success(function(){ ok(true, "success"); })
135                                 .error(function(){ ok(false, "error"); })
136                                 .complete(function(){ start(); });
137                         }
138                 });
139         }, 13);
140 });
141
142 test("jQuery.ajax() - success callbacks (very late binding)", function() {
143         expect( 8 );
144
145         jQuery.ajaxSetup({ timeout: 0 });
146
147         stop();
148
149         setTimeout(function(){
150                 jQuery('#foo').ajaxStart(function(){
151                         ok( true, "ajaxStart" );
152                 }).ajaxStop(function(){
153                         ok( true, "ajaxStop" );
154                 }).ajaxSend(function(){
155                         ok( true, "ajaxSend" );
156                 }).ajaxComplete(function(){
157                         ok( true, "ajaxComplete" );
158                 }).ajaxError(function(){
159                         ok( false, "ajaxError" );
160                 }).ajaxSuccess(function(){
161                         ok( true, "ajaxSuccess" );
162                 });
163
164                 jQuery.ajax({
165                         url: url("data/name.html"),
166                         beforeSend: function(){ ok(true, "beforeSend"); },
167                         complete: function(xhr) {
168                                 setTimeout (function() {
169                                         xhr
170                                         .complete(function(){ ok(true, "complete"); })
171                                         .success(function(){ ok(true, "success"); })
172                                         .error(function(){ ok(false, "error"); })
173                                         .complete(function(){ start(); });
174                                 },100);
175                         }
176                 });
177         }, 13);
178 });
179
180 test("jQuery.ajax() - success callbacks (order)", function() {
181         expect( 1 );
182
183         jQuery.ajaxSetup({ timeout: 0 });
184
185         stop();
186
187         var testString = "";
188
189         setTimeout(function(){
190                 jQuery.ajax({
191                         url: url("data/name.html"),
192                         success: function( _1 , _2 , xhr ) {
193                                 xhr.success(function() {
194                                         xhr.success(function() {
195                                                 testString += "E";
196                                         });
197                                         testString += "D";
198                                 });
199                                 testString += "A";
200                         },
201                         complete: function() {
202                                 strictEqual(testString, "ABCDE", "Proper order");
203                                 start();
204                         }
205                 }).success(function() {
206                         testString += "B";
207                 }).success(function() {
208                         testString += "C";
209                 });
210         }, 13);
211 });
212
213 test("jQuery.ajax() - error callbacks", function() {
214         expect( 8 );
215         stop();
216
217         jQuery('#foo').ajaxStart(function(){
218                 ok( true, "ajaxStart" );
219         }).ajaxStop(function(){
220                 ok( true, "ajaxStop" );
221                 start();
222         }).ajaxSend(function(){
223                 ok( true, "ajaxSend" );
224         }).ajaxComplete(function(){
225                 ok( true, "ajaxComplete" );
226         }).ajaxError(function(){
227                 ok( true, "ajaxError" );
228         }).ajaxSuccess(function(){
229                 ok( false, "ajaxSuccess" );
230         });
231
232         jQuery.ajaxSetup({ timeout: 500 });
233
234         jQuery.ajax({
235                 url: url("data/name.php?wait=5"),
236                 beforeSend: function(){ ok(true, "beforeSend"); },
237                 success: function(){ ok(false, "success"); },
238                 error: function(){ ok(true, "error"); },
239                 complete: function(){ ok(true, "complete"); }
240         });
241 });
242
243 test( "jQuery.ajax - multiple method signatures introduced in 1.5 ( #8107)", function() {
244
245         expect( 4 );
246
247         stop();
248
249         jQuery.when(
250                 jQuery.ajax().success(function() { ok( true, 'With no arguments' ); }),
251                 jQuery.ajax('data/name.html').success(function() { ok( true, 'With only string URL argument' ); }),
252                 jQuery.ajax('data/name.html', {} ).success(function() { ok( true, 'With string URL param and map' ); }),
253                 jQuery.ajax({ url: 'data/name.html'} ).success(function() { ok( true, 'With only map' ); })
254         ).then( start, start );
255
256 });
257
258 test("jQuery.ajax() - textStatus and errorThrown values", function() {
259
260         var nb = 2;
261
262         expect( 2 * nb );
263         stop();
264
265         function startN() {
266                 if ( !( --nb ) ) {
267                         start();
268                 }
269         }
270
271         /*
272         Safari 3.x returns "OK" instead of "Not Found"
273         Safari 4.x doesn't have this issue so the test should be re-instated once
274         we drop support for 3.x
275
276         jQuery.ajax({
277                 url: url("data/nonExistingURL"),
278                 error: function( _ , textStatus , errorThrown ){
279                         strictEqual( textStatus, "error", "textStatus is 'error' for 404" );
280                         strictEqual( errorThrown, "Not Found", "errorThrown is 'Not Found' for 404");
281                         startN();
282                 }
283         });
284         */
285
286         jQuery.ajax({
287                 url: url("data/name.php?wait=5"),
288                 error: function( _ , textStatus , errorThrown ){
289                         strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
290                         strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort");
291                         startN();
292                 }
293         }).abort();
294
295         jQuery.ajax({
296                 url: url("data/name.php?wait=5"),
297                 error: function( _ , textStatus , errorThrown ){
298                         strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
299                         strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')");
300                         startN();
301                 }
302         }).abort( "mystatus" );
303 });
304
305 test("jQuery.ajax() - responseText on error", function() {
306
307         expect( 1 );
308
309         stop();
310
311         jQuery.ajax({
312                 url: url("data/errorWithText.php"),
313                 error: function(xhr) {
314                         strictEqual( xhr.responseText , "plain text message" , "Test jqXHR.responseText is filled for HTTP errors" );
315                 },
316                 complete: function() {
317                         start();
318                 }
319         });
320 });
321
322 test(".ajax() - retry with jQuery.ajax( this )", function() {
323
324         expect( 1 );
325
326         stop();
327
328         var firstTime = 1;
329
330         jQuery.ajax({
331                 url: url("data/errorWithText.php"),
332                 error: function() {
333                         if ( firstTime ) {
334                                 firstTime = 0;
335                                 jQuery.ajax( this );
336                         } else {
337                                 ok( true , "Test retrying with jQuery.ajax(this) works" );
338                                 start();
339                         }
340                 }
341         });
342
343 });
344
345 test(".ajax() - headers" , function() {
346
347         expect( 4 );
348
349         stop();
350
351         jQuery('#foo').ajaxSend(function( evt, xhr ) {
352                 xhr.setRequestHeader( "ajax-send", "test" );
353         });
354
355         var requestHeaders = {
356                         siMPle: "value",
357                         "SometHing-elsE": "other value",
358                         OthEr: "something else"
359                 },
360                 list = [],
361                 i;
362
363         for( i in requestHeaders ) {
364                 list.push( i );
365         }
366         list.push( "ajax-send" );
367
368         jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
369
370                 headers: requestHeaders,
371                 success: function( data , _ , xhr ) {
372                         var tmp = [];
373                         for ( i in requestHeaders ) {
374                                 tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
375                         }
376                         tmp.push(  "ajax-send: test\n" );
377                         tmp = tmp.join( "" );
378
379                         strictEqual( data , tmp , "Headers were sent" );
380                         strictEqual( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
381                         if ( jQuery.browser.mozilla ) {
382                                 ok( true, "Firefox doesn't support empty headers" );
383                         } else {
384                                 strictEqual( xhr.getResponseHeader( "Empty-Header" ) , "" , "Empty header received" );
385                         }
386                         strictEqual( xhr.getResponseHeader( "Sample-Header2" ) , "Hello World 2" , "Second sample header received" );
387                 },
388                 error: function(){ ok(false, "error"); }
389
390         }).then( start, start );
391
392 });
393
394 test(".ajax() - Accept header" , function() {
395
396         expect( 1 );
397
398         stop();
399
400         jQuery.ajax(url("data/headers.php?keys=accept"), {
401                 headers: {
402                         Accept: "very wrong accept value"
403                 },
404                 beforeSend: function( xhr ) {
405                         xhr.setRequestHeader( "Accept", "*/*" );
406                 },
407                 success: function( data ) {
408                         strictEqual( data , "accept: */*\n" , "Test Accept header is set to last value provided" );
409                         start();
410                 },
411                 error: function(){ ok(false, "error"); }
412         });
413
414 });
415
416 test(".ajax() - contentType" , function() {
417
418         expect( 2 );
419
420         stop();
421
422         var count = 2;
423
424         function restart() {
425                 if ( ! --count ) {
426                         start();
427                 }
428         }
429
430         jQuery.ajax(url("data/headers.php?keys=content-type" ), {
431                 contentType: "test",
432                 success: function( data ) {
433                         strictEqual( data , "content-type: test\n" , "Test content-type is sent when options.contentType is set" );
434                 },
435                 complete: function() {
436                         restart();
437                 }
438         });
439
440         jQuery.ajax(url("data/headers.php?keys=content-type" ), {
441                 contentType: false,
442                 success: function( data ) {
443                         strictEqual( data , "content-type: \n" , "Test content-type is not sent when options.contentType===false" );
444                 },
445                 complete: function() {
446                         restart();
447                 }
448         });
449
450 });
451
452 test(".ajax() - protocol-less urls", function() {
453         expect(1);
454
455         jQuery.ajax({
456                 url: "//somedomain.com",
457                 beforeSend: function( xhr, settings ) {
458                         equals(settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added.");
459                         return false;
460                 }
461         });
462 });
463
464 test(".ajax() - hash", function() {
465         expect(3);
466
467         jQuery.ajax({
468                 url: "data/name.html#foo",
469                 beforeSend: function( xhr, settings ) {
470                         equals(settings.url, "data/name.html", "Make sure that the URL is trimmed.");
471                         return false;
472                 }
473         });
474
475         jQuery.ajax({
476                 url: "data/name.html?abc#foo",
477                 beforeSend: function( xhr, settings ) {
478                 equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
479                         return false;
480                 }
481         });
482
483         jQuery.ajax({
484                 url: "data/name.html?abc#foo",
485                 data: { "test": 123 },
486                 beforeSend: function( xhr, settings ) {
487                         equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed.");
488                         return false;
489                 }
490         });
491 });
492
493 test("jQuery ajax - cross-domain detection", function() {
494
495         expect( 5 );
496
497         var loc = document.location,
498                 otherPort = loc.port === 666 ? 667 : 666,
499                 otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
500
501         jQuery.ajax({
502                 dataType: "jsonp",
503                 url: otherProtocol + "//" + loc.host,
504                 beforeSend: function( _ , s ) {
505                         ok( s.crossDomain , "Test different protocols are detected as cross-domain" );
506                         return false;
507                 }
508         });
509
510         jQuery.ajax({
511                 url: 'app:/path',
512                 beforeSend: function( _ , s ) {
513                         ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
514                         return false;
515                 }
516         });
517
518         jQuery.ajax({
519                 dataType: "jsonp",
520                 url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
521                 beforeSend: function( _ , s ) {
522                         ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
523                         return false;
524                 }
525         });
526
527         jQuery.ajax({
528                 dataType: "jsonp",
529                 url: loc.protocol + "//" + loc.hostname + ":" + otherPort,
530                 beforeSend: function( _ , s ) {
531                         ok( s.crossDomain , "Test different ports are detected as cross-domain" );
532                         return false;
533                 }
534         });
535
536         jQuery.ajax({
537                 dataType: "jsonp",
538                 url: loc.protocol + "//" + loc.host,
539                 crossDomain: true,
540                 beforeSend: function( _ , s ) {
541                         ok( s.crossDomain , "Test forced crossDomain is detected as cross-domain" );
542                         return false;
543                 }
544         });
545
546 });
547
548 test(".load() - 404 error callbacks", function() {
549         expect( 6 );
550         stop();
551
552         jQuery('#foo').ajaxStart(function(){
553                 ok( true, "ajaxStart" );
554         }).ajaxStop(function(){
555                 ok( true, "ajaxStop" );
556                 start();
557         }).ajaxSend(function(){
558                 ok( true, "ajaxSend" );
559         }).ajaxComplete(function(){
560                 ok( true, "ajaxComplete" );
561         }).ajaxError(function(){
562                 ok( true, "ajaxError" );
563         }).ajaxSuccess(function(){
564                 ok( false, "ajaxSuccess" );
565         });
566
567         jQuery("<div/>").load("data/404.html", function(){
568                 ok(true, "complete");
569         });
570 });
571
572 test("jQuery.ajax() - abort", function() {
573         expect( 8 );
574         stop();
575
576         jQuery('#foo').ajaxStart(function(){
577                 ok( true, "ajaxStart" );
578         }).ajaxStop(function(){
579                 ok( true, "ajaxStop" );
580                 start();
581         }).ajaxSend(function(){
582                 ok( true, "ajaxSend" );
583         }).ajaxComplete(function(){
584                 ok( true, "ajaxComplete" );
585         });
586
587         var xhr = jQuery.ajax({
588                 url: url("data/name.php?wait=5"),
589                 beforeSend: function(){ ok(true, "beforeSend"); },
590                 complete: function(){ ok(true, "complete"); }
591         });
592
593         equals( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
594
595         xhr.abort();
596         equals( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
597 });
598
599 test("Ajax events with context", function() {
600         expect(14);
601
602         stop();
603         var context = document.createElement("div");
604
605         function event(e){
606                 equals( this, context, e.type );
607         }
608
609         function callback(msg){
610                 return function(){
611                         equals( this, context, "context is preserved on callback " + msg );
612                 };
613         }
614
615         function nocallback(msg){
616                 return function(){
617                         equals( typeof this.url, "string", "context is settings on callback " + msg );
618                 };
619         }
620
621         jQuery('#foo').add(context)
622                         .ajaxSend(event)
623                         .ajaxComplete(event)
624                         .ajaxError(event)
625                         .ajaxSuccess(event);
626
627         jQuery.ajax({
628                 url: url("data/name.html"),
629                 beforeSend: callback("beforeSend"),
630                 success: callback("success"),
631                 error: callback("error"),
632                 complete:function(){
633                         callback("complete").call(this);
634
635                         jQuery.ajax({
636                                 url: url("data/404.html"),
637                                 context: context,
638                                 beforeSend: callback("beforeSend"),
639                                 error: callback("error"),
640                                 complete: function(){
641                                         callback("complete").call(this);
642
643                                         jQuery('#foo').add(context).unbind();
644
645                                         jQuery.ajax({
646                                                 url: url("data/404.html"),
647                                                 beforeSend: nocallback("beforeSend"),
648                                                 error: nocallback("error"),
649                                                 complete: function(){
650                                                         nocallback("complete").call(this);
651                                                         start();
652                                                 }
653                                         });
654                                 }
655                         });
656                 },
657                 context:context
658         });
659 });
660
661 test("jQuery.ajax context modification", function() {
662         expect(1);
663
664         stop();
665
666         var obj = {};
667
668         jQuery.ajax({
669                 url: url("data/name.html"),
670                 context: obj,
671                 beforeSend: function(){
672                         this.test = "foo";
673                 },
674                 complete: function() {
675                         start();
676                 }
677         });
678
679         equals( obj.test, "foo", "Make sure the original object is maintained." );
680 });
681
682 test("jQuery.ajax context modification through ajaxSetup", function() {
683         expect(4);
684
685         stop();
686
687         var obj = {};
688
689         jQuery.ajaxSetup({
690                 context: obj
691         });
692
693         strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." );
694
695         jQuery.ajax({
696                 url: url("data/name.html"),
697                 complete: function() {
698                         strictEqual( this, obj, "Make sure the original object is maintained." );
699                         jQuery.ajax({
700                                 url: url("data/name.html"),
701                                 context: {},
702                                 complete: function() {
703                                         ok( this !== obj, "Make sure overidding context is possible." );
704                                         jQuery.ajaxSetup({
705                                                 context: false
706                                         });
707                                         jQuery.ajax({
708                                                 url: url("data/name.html"),
709                                                 beforeSend: function(){
710                                                         this.test = "foo2";
711                                                 },
712                                                 complete: function() {
713                                                         ok( this !== obj, "Make sure unsetting context is possible." );
714                                                         start();
715                                                 }
716                                         });
717                                 }
718                         });
719                 }
720         });
721 });
722
723 test("jQuery.ajax() - disabled globals", function() {
724         expect( 3 );
725         stop();
726
727         jQuery('#foo').ajaxStart(function(){
728                 ok( false, "ajaxStart" );
729         }).ajaxStop(function(){
730                 ok( false, "ajaxStop" );
731         }).ajaxSend(function(){
732                 ok( false, "ajaxSend" );
733         }).ajaxComplete(function(){
734                 ok( false, "ajaxComplete" );
735         }).ajaxError(function(){
736                 ok( false, "ajaxError" );
737         }).ajaxSuccess(function(){
738                 ok( false, "ajaxSuccess" );
739         });
740
741         jQuery.ajax({
742                 global: false,
743                 url: url("data/name.html"),
744                 beforeSend: function(){ ok(true, "beforeSend"); },
745                 success: function(){ ok(true, "success"); },
746                 error: function(){ ok(false, "error"); },
747                 complete: function(){
748                   ok(true, "complete");
749                   setTimeout(function(){ start(); }, 13);
750                 }
751         });
752 });
753
754 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
755         expect(3);
756         stop();
757         jQuery.ajax({
758           url: url("data/with_fries.xml"),
759           dataType: "xml",
760           success: function(resp) {
761                 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
762                 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
763                 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
764                 start();
765           }
766         });
767 });
768
769 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over JSONP)", function() {
770         expect(3);
771         stop();
772         jQuery.ajax({
773           url: url("data/with_fries_over_jsonp.php"),
774           dataType: "jsonp xml",
775           success: function(resp) {
776                 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
777                 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
778                 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
779                 start();
780           },
781           error: function(_1,_2,error) {
782                 ok( false, error );
783                 start();
784           }
785         });
786 });
787
788 test("jQuery.ajax - HEAD requests", function() {
789         expect(2);
790
791         stop();
792         jQuery.ajax({
793                 url: url("data/name.html"),
794                 type: "HEAD",
795                 success: function(data, status, xhr){
796                         var h = xhr.getAllResponseHeaders();
797                         ok( /Date/i.test(h), 'No Date in HEAD response' );
798
799                         jQuery.ajax({
800                                 url: url("data/name.html"),
801                                 data: { whip_it: "good" },
802                                 type: "HEAD",
803                                 success: function(data, status, xhr){
804                                         var h = xhr.getAllResponseHeaders();
805                                         ok( /Date/i.test(h), 'No Date in HEAD response with data' );
806                                         start();
807                                 }
808                         });
809                 }
810         });
811
812 });
813
814 test("jQuery.ajax - beforeSend", function() {
815         expect(1);
816         stop();
817
818         var check = false;
819
820         jQuery.ajaxSetup({ timeout: 0 });
821
822         jQuery.ajax({
823                 url: url("data/name.html"),
824                 beforeSend: function(xml) {
825                         check = true;
826                 },
827                 success: function(data) {
828                         ok( check, "check beforeSend was executed" );
829                         start();
830                 }
831         });
832 });
833
834 test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
835         expect(2);
836         var request = jQuery.ajax({
837                 url: url("data/name.html"),
838                 beforeSend: function() {
839                         ok( true, "beforeSend got called, canceling" );
840                         return false;
841                 },
842                 success: function() {
843                         ok( false, "request didn't get canceled" );
844                 },
845                 complete: function() {
846                         ok( false, "request didn't get canceled" );
847                 },
848                 error: function() {
849                         ok( false, "request didn't get canceled" );
850                 }
851         });
852         ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
853 });
854
855 test("jQuery.ajax - beforeSend, cancel request manually", function() {
856         expect(2);
857         var request = jQuery.ajax({
858                 url: url("data/name.html"),
859                 beforeSend: function(xhr) {
860                         ok( true, "beforeSend got called, canceling" );
861                         xhr.abort();
862                 },
863                 success: function() {
864                         ok( false, "request didn't get canceled" );
865                 },
866                 complete: function() {
867                         ok( false, "request didn't get canceled" );
868                 },
869                 error: function() {
870                         ok( false, "request didn't get canceled" );
871                 }
872         });
873         ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
874 });
875
876 window.foobar = null;
877 window.testFoo = undefined;
878
879 test("jQuery.ajax - dataType html", function() {
880         expect(5);
881         stop();
882
883         var verifyEvaluation = function() {
884                 equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
885                 equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
886
887                 start();
888         };
889
890         jQuery.ajax({
891           dataType: "html",
892           url: url("data/test.html"),
893           success: function(data) {
894                 jQuery("#ap").html(data);
895                 ok( data.match(/^html text/), 'Check content for datatype html' );
896                 setTimeout(verifyEvaluation, 600);
897           }
898         });
899 });
900
901 test("serialize()", function() {
902         expect(5);
903
904         // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
905         jQuery("#search").after(
906                 '<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+
907                 '<input type="number" id="html5number" name="number" value="43" />'
908         );
909
910         equals( jQuery('#form').serialize(),
911                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
912                 'Check form serialization as query string');
913
914         equals( jQuery('#form :input').serialize(),
915                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
916                 'Check input serialization as query string');
917
918         equals( jQuery('#testForm').serialize(),
919                 'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
920                 'Check form serialization as query string');
921
922         equals( jQuery('#testForm :input').serialize(),
923                 'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
924                 'Check input serialization as query string');
925
926         equals( jQuery('#form, #testForm').serialize(),
927                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
928                 'Multiple form serialization as query string');
929
930   /* Temporarily disabled. Opera 10 has problems with form serialization.
931         equals( jQuery('#form, #testForm :input').serialize(),
932                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
933                 'Mixed form/input serialization as query string');
934         */
935         jQuery("#html5email, #html5number").remove();
936 });
937
938 test("jQuery.param()", function() {
939         expect(24);
940
941         equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
942
943         var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
944         equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
945
946         params = {someName: [1, 2, 3], regularThing: "blah" };
947         equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );
948
949         params = {foo: ['a', 'b', 'c']};
950         equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
951
952         params = {foo: ["baz", 42, "All your base are belong to us"] };
953         equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
954
955         params = {foo: { bar: 'baz', beep: 42, quux: 'All your base are belong to us' } };
956         equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
957
958         params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
959         equals( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure" );
960
961         params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
962         equals( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
963
964         params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
965         equals( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
966
967         equals( decodeURIComponent( jQuery.param({ a: [1,2,3], 'b[]': [4,5,6], 'c[d]': [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
968
969         // Make sure empty arrays and objects are handled #6481
970         equals( jQuery.param({"foo": {"bar": []} }), "foo%5Bbar%5D=", "Empty array param" );
971         equals( jQuery.param({"foo": {"bar": [], foo: 1} }), "foo%5Bbar%5D=&foo%5Bfoo%5D=1", "Empty array param" );
972         equals( jQuery.param({"foo": {"bar": {}} }), "foo%5Bbar%5D=", "Empty object param" );
973
974         // #7945
975         equals( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
976
977         jQuery.ajaxSetup({ traditional: true });
978
979         var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
980         equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
981
982         params = {someName: [1, 2, 3], regularThing: "blah" };
983         equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
984
985         params = {foo: ['a', 'b', 'c']};
986         equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
987
988         params = {"foo[]":["baz", 42, "All your base are belong to us"]};
989         equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
990
991         params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
992         equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
993
994         params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
995         equals( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure" );
996
997         params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
998         equals( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
999
1000         params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
1001         equals( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
1002
1003         params = { param1: null };
1004         equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
1005
1006         params = {'test': {'length': 3, 'foo': 'bar'} };
1007         equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
1008 });
1009
1010 test("synchronous request", function() {
1011         expect(1);
1012         ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );
1013 });
1014
1015 test("synchronous request with callbacks", function() {
1016         expect(2);
1017         var result;
1018         jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } });
1019         ok( /^{ "data"/.test( result ), "check returned text" );
1020 });
1021
1022 test("pass-through request object", function() {
1023         expect(8);
1024         stop();
1025
1026         var target = "data/name.html";
1027         var successCount = 0;
1028         var errorCount = 0;
1029         var errorEx = "";
1030         var success = function() {
1031                 successCount++;
1032         };
1033         jQuery("#foo").ajaxError(function (e, xml, s, ex) {
1034                 errorCount++;
1035                 errorEx += ": " + xml.status;
1036         });
1037         jQuery("#foo").one('ajaxStop', function () {
1038                 equals(successCount, 5, "Check all ajax calls successful");
1039                 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
1040                 jQuery("#foo").unbind('ajaxError');
1041
1042                 start();
1043         });
1044
1045         ok( jQuery.get(url(target), success), "get" );
1046         ok( jQuery.post(url(target), success), "post" );
1047         ok( jQuery.getScript(url("data/test.js"), success), "script" );
1048         ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
1049         ok( jQuery.ajax({url: url(target), success: success}), "generic" );
1050 });
1051
1052 test("ajax cache", function () {
1053         expect(18);
1054
1055         stop();
1056
1057         var count = 0;
1058
1059         jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
1060                 var re = /_=(.*?)(&|$)/g;
1061                 var oldOne = null;
1062                 for (var i = 0; i < 6; i++) {
1063                         var ret = re.exec(s.url);
1064                         if (!ret) {
1065                                 break;
1066                         }
1067                         oldOne = ret[1];
1068                 }
1069                 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
1070                 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
1071                 if(++count == 6)
1072                         start();
1073         });
1074
1075         ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
1076         ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
1077         ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
1078         ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
1079         ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
1080         ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
1081 });
1082
1083 /*
1084  * Test disabled.
1085  * The assertions expect that the passed-in object will be modified,
1086  * which shouldn't be the case. Fixes #5439.
1087 test("global ajaxSettings", function() {
1088         expect(2);
1089
1090         var tmp = jQuery.extend({}, jQuery.ajaxSettings);
1091         var orig = { url: "data/with_fries.xml" };
1092         var t;
1093
1094         jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
1095
1096         t = jQuery.extend({}, orig);
1097         t.data = {};
1098         jQuery.ajax(t);
1099         ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
1100
1101         t = jQuery.extend({}, orig);
1102         t.data = { zoo: 'a', ping: 'b' };
1103         jQuery.ajax(t);
1104         ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" );
1105
1106         jQuery.ajaxSettings = tmp;
1107 });
1108 */
1109
1110 test("load(String)", function() {
1111         expect(1);
1112         stop(); // check if load can be called with only url
1113         jQuery('#first').load("data/name.html", start);
1114 });
1115
1116 test("load('url selector')", function() {
1117         expect(1);
1118         stop(); // check if load can be called with only url
1119         jQuery('#first').load("data/test3.html div.user", function(){
1120                 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
1121                 start();
1122         });
1123 });
1124
1125 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
1126         expect(1);
1127         stop();
1128         jQuery.ajaxSetup({ dataType: "json" });
1129         jQuery("#first").ajaxComplete(function (e, xml, s) {
1130                 equals( s.dataType, "html", "Verify the load() dataType was html" );
1131                 jQuery("#first").unbind("ajaxComplete");
1132                 jQuery.ajaxSetup({ dataType: "" });
1133                 start();
1134         });
1135         jQuery('#first').load("data/test3.html");
1136 });
1137
1138 test("load(String, Function) - simple: inject text into DOM", function() {
1139         expect(2);
1140         stop();
1141         jQuery('#first').load(url("data/name.html"), function() {
1142                 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
1143                 start();
1144         });
1145 });
1146
1147 test("load(String, Function) - check scripts", function() {
1148         expect(7);
1149         stop();
1150
1151         var verifyEvaluation = function() {
1152                 equals( foobar, "bar", 'Check if script src was evaluated after load' );
1153                 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
1154
1155                 start();
1156         };
1157         jQuery('#first').load(url('data/test.html'), function() {
1158                 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
1159                 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1160                 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1161                 setTimeout(verifyEvaluation, 600);
1162         });
1163 });
1164
1165 test("load(String, Function) - check file with only a script tag", function() {
1166         expect(3);
1167         stop();
1168
1169         jQuery('#first').load(url('data/test2.html'), function() {
1170                 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1171                 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1172
1173                 start();
1174         });
1175 });
1176
1177 test("load(String, Function) - dataFilter in ajaxSettings", function() {
1178         expect(2);
1179         stop();
1180         jQuery.ajaxSetup({ dataFilter: function() { return "Hello World"; } });
1181         var div = jQuery("<div/>").load(url("data/name.html"), function(responseText) {
1182                 strictEqual( div.html(), "Hello World" , "Test div was filled with filtered data" );
1183                 strictEqual( responseText, "Hello World" , "Test callback receives filtered data" );
1184                 jQuery.ajaxSetup({ dataFilter: 0 });
1185                 start();
1186         });
1187 });
1188
1189 test("load(String, Object, Function)", function() {
1190         expect(2);
1191         stop();
1192
1193         jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
1194                 var $post = jQuery(this).find('#post');
1195                 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
1196                 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
1197                 start();
1198         });
1199 });
1200
1201 test("load(String, String, Function)", function() {
1202         expect(2);
1203         stop();
1204
1205         jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
1206                 var $get = jQuery(this).find('#get');
1207                 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
1208                 equals( $get.find('#bar').text(), 'ok', 'Check if a      of data is passed correctly');
1209                 start();
1210         });
1211 });
1212
1213 test("jQuery.get(String, Function) - data in ajaxSettings (#8277)", function() {
1214         expect(1);
1215         stop();
1216         jQuery.ajaxSetup({
1217                 data: "helloworld"
1218         });
1219         jQuery.get(url('data/echoQuery.php'), function(data) {
1220                 ok( /helloworld$/.test( data ), 'Data from ajaxSettings was used');
1221                 jQuery.ajaxSetup({
1222                         data: null
1223                 });
1224                 start();
1225         });
1226 });
1227
1228 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
1229         expect(2);
1230         stop();
1231         jQuery.get(url('data/dashboard.xml'), function(xml) {
1232                 var content = [];
1233                 jQuery('tab', xml).each(function() {
1234                         content.push(jQuery(this).text());
1235                 });
1236                 equals( content[0], 'blabla', 'Check first tab');
1237                 equals( content[1], 'blublu', 'Check second tab');
1238                 start();
1239         });
1240 });
1241
1242 test("jQuery.getScript(String, Function) - with callback", function() {
1243         expect(3);
1244         stop();
1245         jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) {
1246                 equals( foobar, "bar", 'Check if script was evaluated' );
1247                 strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
1248                 setTimeout(start, 100);
1249         });
1250 });
1251
1252 test("jQuery.getScript(String, Function) - no callback", function() {
1253         expect(1);
1254         stop();
1255         jQuery.getScript(url("data/test.js"), function(){
1256                 start();
1257         });
1258 });
1259
1260 jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) {
1261
1262         test("jQuery.ajax() - JSONP, " + label, function() {
1263                 expect(20);
1264
1265                 var count = 0;
1266                 function plus(){ if ( ++count == 18 ) start(); }
1267
1268                 stop();
1269
1270                 jQuery.ajax({
1271                         url: "data/jsonp.php",
1272                         dataType: "jsonp",
1273                         crossDomain: crossDomain,
1274                         success: function(data){
1275                                 ok( data.data, "JSON results returned (GET, no callback)" );
1276                                 plus();
1277                         },
1278                         error: function(data){
1279                                 ok( false, "Ajax error JSON (GET, no callback)" );
1280                                 plus();
1281                         }
1282                 });
1283
1284                 jQuery.ajax({
1285                         url: "data/jsonp.php?callback=?",
1286                         dataType: "jsonp",
1287                         crossDomain: crossDomain,
1288                         success: function(data){
1289                                 ok( data.data, "JSON results returned (GET, url callback)" );
1290                                 plus();
1291                         },
1292                         error: function(data){
1293                                 ok( false, "Ajax error JSON (GET, url callback)" );
1294                                 plus();
1295                         }
1296                 });
1297
1298                 jQuery.ajax({
1299                         url: "data/jsonp.php",
1300                         dataType: "jsonp",
1301                         crossDomain: crossDomain,
1302                         data: "callback=?",
1303                         success: function(data){
1304                                 ok( data.data, "JSON results returned (GET, data callback)" );
1305                                 plus();
1306                         },
1307                         error: function(data){
1308                                 ok( false, "Ajax error JSON (GET, data callback)" );
1309                                 plus();
1310                         }
1311                 });
1312
1313                 jQuery.ajax({
1314                         url: "data/jsonp.php?callback=??",
1315                         dataType: "jsonp",
1316                         crossDomain: crossDomain,
1317                         success: function(data){
1318                                 ok( data.data, "JSON results returned (GET, url context-free callback)" );
1319                                 plus();
1320                         },
1321                         error: function(data){
1322                                 ok( false, "Ajax error JSON (GET, url context-free callback)" );
1323                                 plus();
1324                         }
1325                 });
1326
1327                 jQuery.ajax({
1328                         url: "data/jsonp.php",
1329                         dataType: "jsonp",
1330                         crossDomain: crossDomain,
1331                         data: "callback=??",
1332                         success: function(data){
1333                                 ok( data.data, "JSON results returned (GET, data context-free callback)" );
1334                                 plus();
1335                         },
1336                         error: function(data){
1337                                 ok( false, "Ajax error JSON (GET, data context-free callback)" );
1338                                 plus();
1339                         }
1340                 });
1341
1342                 jQuery.ajax({
1343                         url: "data/jsonp.php/??",
1344                         dataType: "jsonp",
1345                         crossDomain: crossDomain,
1346                         success: function(data){
1347                                 ok( data.data, "JSON results returned (GET, REST-like)" );
1348                                 plus();
1349                         },
1350                         error: function(data){
1351                                 ok( false, "Ajax error JSON (GET, REST-like)" );
1352                                 plus();
1353                         }
1354                 });
1355
1356                 jQuery.ajax({
1357                         url: "data/jsonp.php/???json=1",
1358                         dataType: "jsonp",
1359                         crossDomain: crossDomain,
1360                         success: function(data){
1361                                 strictEqual( jQuery.type(data), "array", "JSON results returned (GET, REST-like with param)" );
1362                                 plus();
1363                         },
1364                         error: function(data){
1365                                 ok( false, "Ajax error JSON (GET, REST-like with param)" );
1366                                 plus();
1367                         }
1368                 });
1369
1370                 jQuery.ajax({
1371                         url: "data/jsonp.php",
1372                         dataType: "jsonp",
1373                         crossDomain: crossDomain,
1374                         jsonp: "callback",
1375                         success: function(data){
1376                                 ok( data.data, "JSON results returned (GET, data obj callback)" );
1377                                 plus();
1378                         },
1379                         error: function(data){
1380                                 ok( false, "Ajax error JSON (GET, data obj callback)" );
1381                                 plus();
1382                         }
1383                 });
1384
1385                 window.jsonpResults = function(data) {
1386                         ok( data.data, "JSON results returned (GET, custom callback function)" );
1387                         window.jsonpResults = undefined;
1388                         plus();
1389                 };
1390
1391                 jQuery.ajax({
1392                         url: "data/jsonp.php",
1393                         dataType: "jsonp",
1394                         crossDomain: crossDomain,
1395                         jsonpCallback: "jsonpResults",
1396                         success: function(data){
1397                                 ok( data.data, "JSON results returned (GET, custom callback name)" );
1398                                 plus();
1399                         },
1400                         error: function(data){
1401                                 ok( false, "Ajax error JSON (GET, custom callback name)" );
1402                                 plus();
1403                         }
1404                 });
1405
1406                 jQuery.ajax({
1407                         url: "data/jsonp.php",
1408                         dataType: "jsonp",
1409                         crossDomain: crossDomain,
1410                         jsonpCallback: "functionToCleanUp",
1411                         success: function(data){
1412                                 ok( data.data, "JSON results returned (GET, custom callback name to be cleaned up)" );
1413                                 strictEqual( window.functionToCleanUp, undefined, "Callback was removed (GET, custom callback name to be cleaned up)" );
1414                                 plus();
1415                                 var xhr;
1416                                 jQuery.ajax({
1417                                         url: "data/jsonp.php",
1418                                         dataType: "jsonp",
1419                                         crossDomain: crossDomain,
1420                                         jsonpCallback: "functionToCleanUp",
1421                                         beforeSend: function( jqXHR ) {
1422                                                 xhr = jqXHR;
1423                                                 return false;
1424                                         }
1425                                 });
1426                                 xhr.error(function() {
1427                                         ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
1428                                         strictEqual( window.functionToCleanUp, undefined, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
1429                                         plus();
1430                                 });
1431                         },
1432                         error: function(data){
1433                                 ok( false, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
1434                                 plus();
1435                         }
1436                 });
1437
1438                 jQuery.ajax({
1439                         type: "POST",
1440                         url: "data/jsonp.php",
1441                         dataType: "jsonp",
1442                         crossDomain: crossDomain,
1443                         success: function(data){
1444                                 ok( data.data, "JSON results returned (POST, no callback)" );
1445                                 plus();
1446                         },
1447                         error: function(data){
1448                                 ok( false, "Ajax error JSON (GET, data obj callback)" );
1449                                 plus();
1450                         }
1451                 });
1452
1453                 jQuery.ajax({
1454                         type: "POST",
1455                         url: "data/jsonp.php",
1456                         data: "callback=?",
1457                         dataType: "jsonp",
1458                         crossDomain: crossDomain,
1459                         success: function(data){
1460                                 ok( data.data, "JSON results returned (POST, data callback)" );
1461                                 plus();
1462                         },
1463                         error: function(data){
1464                                 ok( false, "Ajax error JSON (POST, data callback)" );
1465                                 plus();
1466                         }
1467                 });
1468
1469                 jQuery.ajax({
1470                         type: "POST",
1471                         url: "data/jsonp.php",
1472                         jsonp: "callback",
1473                         dataType: "jsonp",
1474                         crossDomain: crossDomain,
1475                         success: function(data){
1476                                 ok( data.data, "JSON results returned (POST, data obj callback)" );
1477                                 plus();
1478                         },
1479                         error: function(data){
1480                                 ok( false, "Ajax error JSON (POST, data obj callback)" );
1481                                 plus();
1482                         }
1483                 });
1484
1485                 //#7578
1486                 jQuery.ajax({
1487                         url: "data/jsonp.php",
1488                         dataType: "jsonp",
1489                         crossDomain: crossDomain,
1490                         beforeSend: function(){
1491                                 strictEqual( this.cache, false, "cache must be false on JSON request" );
1492                                 plus();
1493                                 return false;
1494                         }
1495                 });
1496
1497                 jQuery.ajax({
1498                         url: "data/jsonp.php?callback=XXX",
1499                         dataType: "jsonp",
1500                         jsonp: false,
1501                         jsonpCallback: "XXX",
1502                         crossDomain: crossDomain,
1503                         beforeSend: function() {
1504                                 ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ) ,
1505                                         "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
1506                                 plus();
1507                         },
1508                         success: function(data){
1509                                 ok( data.data, "JSON results returned (GET, custom callback name with no url manipulation)" );
1510                                 plus();
1511                         },
1512                         error: function(data){
1513                                 ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
1514                                 plus();
1515                         }
1516                 });
1517
1518         });
1519 });
1520
1521 test("jQuery.ajax() - script, Remote", function() {
1522         expect(2);
1523
1524         var base = window.location.href.replace(/[^\/]*$/, "");
1525
1526         stop();
1527
1528         jQuery.ajax({
1529                 url: base + "data/test.js",
1530                 dataType: "script",
1531                 success: function(data){
1532                         ok( foobar, "Script results returned (GET, no callback)" );
1533                         start();
1534                 }
1535         });
1536 });
1537
1538 test("jQuery.ajax() - script, Remote with POST", function() {
1539         expect(3);
1540
1541         var base = window.location.href.replace(/[^\/]*$/, "");
1542
1543         stop();
1544
1545         jQuery.ajax({
1546                 url: base + "data/test.js",
1547                 type: "POST",
1548                 dataType: "script",
1549                 success: function(data, status){
1550                         ok( foobar, "Script results returned (POST, no callback)" );
1551                         equals( status, "success", "Script results returned (POST, no callback)" );
1552                         start();
1553                 },
1554                 error: function(xhr) {
1555                         ok( false, "ajax error, status code: " + xhr.status );
1556                         start();
1557                 }
1558         });
1559 });
1560
1561 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
1562         expect(2);
1563
1564         var base = window.location.href.replace(/[^\/]*$/, "");
1565         base = base.replace(/^.*?\/\//, "//");
1566
1567         stop();
1568
1569         jQuery.ajax({
1570                 url: base + "data/test.js",
1571                 dataType: "script",
1572                 success: function(data){
1573                         ok( foobar, "Script results returned (GET, no callback)" );
1574                         start();
1575                 }
1576         });
1577 });
1578
1579 test("jQuery.ajax() - malformed JSON", function() {
1580         expect(2);
1581
1582         stop();
1583
1584         jQuery.ajax({
1585                 url: "data/badjson.js",
1586                 dataType: "json",
1587                 success: function(){
1588                         ok( false, "Success." );
1589                         start();
1590                 },
1591                 error: function(xhr, msg, detailedMsg) {
1592                         equals( "parsererror", msg, "A parse error occurred." );
1593                         ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" );
1594                         start();
1595                 }
1596         });
1597 });
1598
1599 test("jQuery.ajax() - script by content-type", function() {
1600         expect(2);
1601
1602         stop();
1603
1604         jQuery.when(
1605
1606                 jQuery.ajax({
1607                         url: "data/script.php",
1608                         data: { header: "script" }
1609                 }),
1610
1611                 jQuery.ajax({
1612                         url: "data/script.php",
1613                         data: { header: "ecma" }
1614                 })
1615
1616         ).then( start, start );
1617 });
1618
1619 test("jQuery.ajax() - json by content-type", function() {
1620         expect(5);
1621
1622         stop();
1623
1624         jQuery.ajax({
1625                 url: "data/json.php",
1626                 data: { header: "json", json: "array" },
1627                 success: function( json ) {
1628                         ok( json.length >= 2, "Check length");
1629                         equals( json[0].name, 'John', 'Check JSON: first, name' );
1630                         equals( json[0].age, 21, 'Check JSON: first, age' );
1631                         equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1632                         equals( json[1].age, 25, 'Check JSON: second, age' );
1633                         start();
1634                 }
1635         });
1636 });
1637
1638 test("jQuery.ajax() - json by content-type disabled with options", function() {
1639         expect(6);
1640
1641         stop();
1642
1643         jQuery.ajax({
1644                 url: url("data/json.php"),
1645                 data: { header: "json", json: "array" },
1646                 contents: {
1647                         json: false
1648                 },
1649                 success: function( text ) {
1650                         equals( typeof text , "string" , "json wasn't auto-determined" );
1651                         var json = jQuery.parseJSON( text );
1652                         ok( json.length >= 2, "Check length");
1653                         equals( json[0].name, 'John', 'Check JSON: first, name' );
1654                         equals( json[0].age, 21, 'Check JSON: first, age' );
1655                         equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1656                         equals( json[1].age, 25, 'Check JSON: second, age' );
1657                         start();
1658                 }
1659         });
1660 });
1661
1662 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
1663         expect(5);
1664         stop();
1665         jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
1666           ok( json.length >= 2, "Check length");
1667           equals( json[0].name, 'John', 'Check JSON: first, name' );
1668           equals( json[0].age, 21, 'Check JSON: first, age' );
1669           equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1670           equals( json[1].age, 25, 'Check JSON: second, age' );
1671           start();
1672         });
1673 });
1674
1675 test("jQuery.getJSON(String, Function) - JSON object", function() {
1676         expect(2);
1677         stop();
1678         jQuery.getJSON(url("data/json.php"), function(json) {
1679           if (json && json.data) {
1680                   equals( json.data.lang, 'en', 'Check JSON: lang' );
1681                   equals( json.data.length, 25, 'Check JSON: length' );
1682           }
1683           start();
1684         });
1685 });
1686
1687 test("jQuery.getJSON - Using Native JSON", function() {
1688         expect(2);
1689
1690         var old = window.JSON;
1691         JSON = {
1692                 parse: function(str){
1693                         ok( true, "Verifying that parse method was run" );
1694                         return true;
1695                 }
1696         };
1697
1698         stop();
1699         jQuery.getJSON(url("data/json.php"), function(json) {
1700                 window.JSON = old;
1701                 equals( json, true, "Verifying return value" );
1702                 start();
1703         });
1704 });
1705
1706 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
1707         expect(2);
1708
1709         var base = window.location.href.replace(/[^\/]*$/, "");
1710
1711         stop();
1712         jQuery.getJSON(url(base + "data/json.php"), function(json) {
1713           equals( json.data.lang, 'en', 'Check JSON: lang' );
1714           equals( json.data.length, 25, 'Check JSON: length' );
1715           start();
1716         });
1717 });
1718
1719 test("jQuery.post - data", 3, function() {
1720         stop();
1721
1722         jQuery.when(
1723                 jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) {
1724                         jQuery( 'math', xml ).each( function() {
1725                                 equals( jQuery( 'calculation', this ).text(), '5-2', 'Check for XML' );
1726                                 equals( jQuery( 'result', this ).text(), '3', 'Check for XML' );
1727                         });
1728                 }),
1729
1730                 jQuery.ajax({
1731                         url: url('data/echoData.php'),
1732                         type: "POST",
1733                         data: {
1734                                 'test': {
1735                                         'length': 7,
1736                                                 'foo': 'bar'
1737                                 }
1738                         },
1739                         success: function( data ) {
1740                                 strictEqual( data, 'test%5Blength%5D=7&test%5Bfoo%5D=bar', 'Check if a sub-object with a length param is serialized correctly');
1741                         }
1742                 })
1743         ).then( start, start );
1744
1745 });
1746
1747 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
1748         expect(4);
1749         stop();
1750         var done = 0;
1751
1752         jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
1753           jQuery('math', xml).each(function() {
1754                         equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1755                         equals( jQuery('result', this).text(), '3', 'Check for XML' );
1756                  });
1757           if ( ++done === 2 ) start();
1758         });
1759
1760         jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
1761           jQuery('math', xml).each(function() {
1762                         equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1763                         equals( jQuery('result', this).text(), '3', 'Check for XML' );
1764                  });
1765           if ( ++done === 2 ) start();
1766         });
1767 });
1768
1769 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
1770         stop();
1771
1772         var passed = 0;
1773
1774         jQuery.ajaxSetup({timeout: 1000});
1775
1776         var pass = function() {
1777                 passed++;
1778                 if ( passed == 2 ) {
1779                         ok( true, 'Check local and global callbacks after timeout' );
1780                         jQuery('#main').unbind("ajaxError");
1781                         start();
1782                 }
1783         };
1784
1785         var fail = function(a,b,c) {
1786                 ok( false, 'Check for timeout failed ' + a + ' ' + b );
1787                 start();
1788         };
1789
1790         jQuery('#main').ajaxError(pass);
1791
1792         jQuery.ajax({
1793           type: "GET",
1794           url: url("data/name.php?wait=5"),
1795           error: pass,
1796           success: fail
1797         });
1798
1799         // reset timeout
1800         jQuery.ajaxSetup({timeout: 0});
1801 });
1802
1803 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
1804         stop();
1805         jQuery.ajaxSetup({timeout: 50});
1806
1807         jQuery.ajax({
1808           type: "GET",
1809           timeout: 15000,
1810           url: url("data/name.php?wait=1"),
1811           error: function() {
1812                    ok( false, 'Check for local timeout failed' );
1813                    start();
1814           },
1815           success: function() {
1816                 ok( true, 'Check for local timeout' );
1817                 start();
1818           }
1819         });
1820
1821         // reset timeout
1822         jQuery.ajaxSetup({timeout: 0});
1823 });
1824
1825 test("jQuery.ajax - simple get", function() {
1826         expect(1);
1827         stop();
1828         jQuery.ajax({
1829           type: "GET",
1830           url: url("data/name.php?name=foo"),
1831           success: function(msg){
1832                 equals( msg, 'bar', 'Check for GET' );
1833                 start();
1834           }
1835         });
1836 });
1837
1838 test("jQuery.ajax - simple post", function() {
1839         expect(1);
1840         stop();
1841         jQuery.ajax({
1842           type: "POST",
1843           url: url("data/name.php"),
1844           data: "name=peter",
1845           success: function(msg){
1846                 equals( msg, 'pan', 'Check for POST' );
1847                 start();
1848           }
1849         });
1850 });
1851
1852 test("ajaxSetup()", function() {
1853         expect(1);
1854         stop();
1855         jQuery.ajaxSetup({
1856                 url: url("data/name.php?name=foo"),
1857                 success: function(msg){
1858                         equals( msg, 'bar', 'Check for GET' );
1859                         start();
1860                 }
1861         });
1862         jQuery.ajax();
1863 });
1864
1865 /*
1866 test("custom timeout does not set error message when timeout occurs, see #970", function() {
1867         stop();
1868         jQuery.ajax({
1869                 url: "data/name.php?wait=1",
1870                 timeout: 500,
1871                 error: function(request, status) {
1872                         ok( status != null, "status shouldn't be null in error handler" );
1873                         equals( "timeout", status );
1874                         start();
1875                 }
1876         });
1877 });
1878 */
1879
1880 test("data option: evaluate function values (#2806)", function() {
1881         stop();
1882         jQuery.ajax({
1883                 url: "data/echoQuery.php",
1884                 data: {
1885                         key: function() {
1886                                 return "value";
1887                         }
1888                 },
1889                 success: function(result) {
1890                         equals( result, "key=value" );
1891                         start();
1892                 }
1893         });
1894 });
1895
1896 test("data option: empty bodies for non-GET requests", function() {
1897         stop();
1898         jQuery.ajax({
1899                 url: "data/echoData.php",
1900                 data: undefined,
1901                 type: "post",
1902                 success: function(result) {
1903                         equals( result, "" );
1904                         start();
1905                 }
1906         });
1907 });
1908
1909 var ifModifiedNow = new Date();
1910
1911 jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ) {
1912
1913         test("jQuery.ajax - If-Modified-Since support" + label, function() {
1914                 expect( 3 );
1915
1916                 stop();
1917
1918                 var url = "data/if_modified_since.php?ts=" + ifModifiedNow++;
1919
1920                 jQuery.ajax({
1921                         url: url,
1922                         ifModified: true,
1923                         cache: cache,
1924                         success: function(data, status) {
1925                                 equals(status, "success" );
1926
1927                                 jQuery.ajax({
1928                                         url: url,
1929                                         ifModified: true,
1930                                         cache: cache,
1931                                         success: function(data, status) {
1932                                                 if ( data === "FAIL" ) {
1933                                                         ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1934                                                         ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1935                                                 } else {
1936                                                         equals(status, "notmodified");
1937                                                         ok(data == null, "response body should be empty");
1938                                                 }
1939                                                 start();
1940                                 },
1941                                         error: function() {
1942                                                 // Do this because opera simply refuses to implement 304 handling :(
1943                                                 // A feature-driven way of detecting this would be appreciated
1944                                                 // See: http://gist.github.com/599419
1945                                                 ok(jQuery.browser.opera, "error");
1946                                                 ok(jQuery.browser.opera, "error");
1947                                                 start();
1948                                         }
1949                                 });
1950                         },
1951                         error: function() {
1952                                 equals(false, "error");
1953                                 // Do this because opera simply refuses to implement 304 handling :(
1954                                 // A feature-driven way of detecting this would be appreciated
1955                                 // See: http://gist.github.com/599419
1956                                 ok(jQuery.browser.opera, "error");
1957                                 start();
1958                         }
1959                 });
1960         });
1961
1962         test("jQuery.ajax - Etag support" + label, function() {
1963                 expect( 3 );
1964
1965                 stop();
1966
1967                 var url = "data/etag.php?ts=" + ifModifiedNow++;
1968
1969                 jQuery.ajax({
1970                         url: url,
1971                         ifModified: true,
1972                         cache: cache,
1973                         success: function(data, status) {
1974                                 equals(status, "success" );
1975
1976                                 jQuery.ajax({
1977                                         url: url,
1978                                         ifModified: true,
1979                                         cache: cache,
1980                                         success: function(data, status) {
1981                                                 if ( data === "FAIL" ) {
1982                                                         ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1983                                                         ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1984                                                 } else {
1985                                                         equals(status, "notmodified");
1986                                                         ok(data == null, "response body should be empty");
1987                                                 }
1988                                                 start();
1989                                 },
1990                                 error: function() {
1991                                                 // Do this because opera simply refuses to implement 304 handling :(
1992                                                 // A feature-driven way of detecting this would be appreciated
1993                                                 // See: http://gist.github.com/599419
1994                                                 ok(jQuery.browser.opera, "error");
1995                                                 ok(jQuery.browser.opera, "error");
1996                                                 start();
1997                                         }
1998                                 });
1999                         },
2000                         error: function() {
2001                                 // Do this because opera simply refuses to implement 304 handling :(
2002                                 // A feature-driven way of detecting this would be appreciated
2003                                 // See: http://gist.github.com/599419
2004                                 ok(jQuery.browser.opera, "error");
2005                                 start();
2006                         }
2007                 });
2008         });
2009 });
2010
2011 test("jQuery ajax - failing cross-domain", function() {
2012
2013         expect( 2 );
2014
2015         stop();
2016
2017         var i = 2;
2018
2019         jQuery.ajax({
2020                 url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
2021                 success: function(){ ok( false , "success" ); },
2022                 error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
2023                 complete: function() { if ( ! --i ) start(); }
2024         });
2025
2026         jQuery.ajax({
2027                 url: 'http://www.google.com',
2028                 success: function(){ ok( false , "success" ); },
2029                 error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
2030                 complete: function() { if ( ! --i ) start(); }
2031         });
2032
2033 });
2034
2035 test("jQuery ajax - atom+xml", function() {
2036
2037         stop();
2038
2039         jQuery.ajax({
2040                 url: url( 'data/atom+xml.php' ),
2041                 success: function(){ ok( true , "success" ); },
2042                 error: function(){ ok( false , "error" ); },
2043                 complete: function() { start(); }
2044         });
2045
2046 });
2047
2048 test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
2049         var success = false;
2050         try {
2051                 var xhr = jQuery.ajax({ url: window.location });
2052                 success = true;
2053                 xhr.abort();
2054         } catch (e) {}
2055
2056         ok( success, "document.location did not generate exception" );
2057 });
2058
2059 test( "jQuery.ajax - statusCode" , function() {
2060
2061         var count = 12;
2062
2063         expect( 20 );
2064         stop();
2065
2066         function countComplete() {
2067                 if ( ! --count ) {
2068                         start();
2069                 }
2070         }
2071
2072         function createStatusCodes( name , isSuccess ) {
2073                 name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
2074                 return {
2075                         200: function() {
2076                                 ok( isSuccess , name );
2077                         },
2078                         404: function() {
2079                                 ok( ! isSuccess , name );
2080                         }
2081                 };
2082         }
2083
2084         jQuery.each( {
2085                 "data/name.html": true,
2086                 "data/someFileThatDoesNotExist.html": false
2087         } , function( uri , isSuccess ) {
2088
2089                 jQuery.ajax( url( uri ) , {
2090                         statusCode: createStatusCodes( "in options" , isSuccess ),
2091                         complete: countComplete
2092                 });
2093
2094                 jQuery.ajax( url( uri ) , {
2095                         complete: countComplete
2096                 }).statusCode( createStatusCodes( "immediately with method" , isSuccess ) );
2097
2098                 jQuery.ajax( url( uri ) , {
2099                         complete: function(jqXHR) {
2100                                 jqXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) );
2101                                 countComplete();
2102                         }
2103                 });
2104
2105                 jQuery.ajax( url( uri ) , {
2106                         complete: function(jqXHR) {
2107                                 setTimeout( function() {
2108                                         jqXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) );
2109                                         countComplete();
2110                                 } , 100 );
2111                         }
2112                 });
2113
2114                 jQuery.ajax( url( uri ) , {
2115                         statusCode: createStatusCodes( "all (options)" , isSuccess ),
2116                         complete: function(jqXHR) {
2117                                 jqXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) );
2118                                 setTimeout( function() {
2119                                         jqXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) );
2120                                         countComplete();
2121                                 } , 100 );
2122                         }
2123                 }).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) );
2124
2125                 var testString = "";
2126
2127                 jQuery.ajax( url( uri ), {
2128                         success: function( a , b , jqXHR ) {
2129                                 ok( isSuccess , "success" );
2130                                 var statusCode = {};
2131                                 statusCode[ jqXHR.status ] = function() {
2132                                         testString += "B";
2133                                 };
2134                                 jqXHR.statusCode( statusCode );
2135                                 testString += "A";
2136                         },
2137                         error: function( jqXHR ) {
2138                                 ok( ! isSuccess , "error" );
2139                                 var statusCode = {};
2140                                 statusCode[ jqXHR.status ] = function() {
2141                                         testString += "B";
2142                                 };
2143                                 jqXHR.statusCode( statusCode );
2144                                 testString += "A";
2145                         },
2146                         complete: function() {
2147                                 strictEqual( testString , "AB" , "Test statusCode callbacks are ordered like " +
2148                                                 ( isSuccess ? "success" :  "error" ) + " callbacks" );
2149                                 countComplete();
2150                         }
2151                 } );
2152
2153         });
2154 });
2155
2156 test("jQuery.ajax - transitive conversions", function() {
2157
2158         expect( 8 );
2159
2160         stop();
2161
2162         jQuery.when(
2163
2164                 jQuery.ajax( url("data/json.php") , {
2165                         converters: {
2166                                 "json myJson": function( data ) {
2167                                         ok( true , "converter called" );
2168                                         return data;
2169                                 }
2170                         },
2171                         dataType: "myJson",
2172                         success: function() {
2173                                 ok( true , "Transitive conversion worked" );
2174                                 strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" );
2175                                 strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType" );
2176                         }
2177                 }),
2178
2179                 jQuery.ajax( url("data/json.php") , {
2180                         converters: {
2181                                 "json myJson": function( data ) {
2182                                         ok( true , "converter called (*)" );
2183                                         return data;
2184                                 }
2185                         },
2186                         contents: false, /* headers are wrong so we ignore them */
2187                         dataType: "* myJson",
2188                         success: function() {
2189                                 ok( true , "Transitive conversion worked (*)" );
2190                                 strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" );
2191                                 strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType (*)" );
2192                         }
2193                 })
2194
2195         ).then( start , start );
2196
2197 });
2198
2199 test("jQuery.ajax - overrideMimeType", function() {
2200
2201         expect( 2 );
2202
2203         stop();
2204
2205         jQuery.when(
2206
2207                 jQuery.ajax( url("data/json.php") , {
2208                         beforeSend: function( xhr ) {
2209                                 xhr.overrideMimeType( "application/json" );
2210                         },
2211                         success: function( json ) {
2212                                 ok( json.data , "Mimetype overriden using beforeSend" );
2213                         }
2214                 }),
2215
2216                 jQuery.ajax( url("data/json.php") , {
2217                         mimeType: "application/json",
2218                         success: function( json ) {
2219                                 ok( json.data , "Mimetype overriden using mimeType option" );
2220                         }
2221                 })
2222
2223         ).then( start , start );
2224
2225 });
2226
2227 test("jQuery.ajax - abort in prefilter", function() {
2228
2229         expect( 1 );
2230
2231         jQuery.ajaxPrefilter(function( options, _, jqXHR ) {
2232                 if ( options.abortInPrefilter ) {
2233                         jqXHR.abort();
2234                 }
2235         });
2236
2237         strictEqual( jQuery.ajax({
2238                 abortInPrefilter: true,
2239                 error: function() {
2240                         ok( false, "error callback called" );
2241                 }
2242         }), false, "Request was properly aborted early by the prefilter" );
2243
2244 });
2245
2246 test("jQuery.ajax - active counter", function() {
2247     ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
2248 });
2249
2250 }
2251
2252 //}