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