Remove an invalid ajax test and some code that is no longer used by any test.
[jquery.git] / test / unit / ajax.js
1 module("ajax", { teardown: moduleTeardown });
2
3 // Safari 3 randomly crashes when running these tests,
4 // but only in the full suite - you can run just the Ajax
5 // tests and they'll pass
6 //if ( !jQuery.browser.safari ) {
7
8 if ( !isLocal ) {
9
10 test("jQuery.ajax() - success callbacks", function() {
11         expect( 8 );
12
13         jQuery.ajaxSetup({ timeout: 0 });
14
15         stop();
16
17         jQuery('#foo').ajaxStart(function(){
18                 ok( true, "ajaxStart" );
19         }).ajaxStop(function(){
20                 ok( true, "ajaxStop" );
21                 start();
22         }).ajaxSend(function(){
23                 ok( true, "ajaxSend" );
24         }).ajaxComplete(function(){
25                 ok( true, "ajaxComplete" );
26         }).ajaxError(function(){
27                 ok( false, "ajaxError" );
28         }).ajaxSuccess(function(){
29                 ok( true, "ajaxSuccess" );
30         });
31
32         jQuery.ajax({
33                 url: url("data/name.html"),
34                 beforeSend: function(){ ok(true, "beforeSend"); },
35                 success: function(){ ok(true, "success"); },
36                 error: function(){ ok(false, "error"); },
37                 complete: function(){ ok(true, "complete"); }
38         });
39 });
40
41 test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
42         expect( 8 );
43
44         jQuery.ajaxSetup({ timeout: 0 });
45
46         stop();
47
48         setTimeout(function(){
49                 jQuery('#foo').ajaxStart(function(){
50                         ok( true, "ajaxStart" );
51                 }).ajaxStop(function(){
52                         ok( true, "ajaxStop" );
53                         start();
54                 }).ajaxSend(function(){
55                         ok( true, "ajaxSend" );
56                 }).ajaxComplete(function(){
57                         ok( true, "ajaxComplete" );
58                 }).ajaxError(function(){
59                         ok( false, "ajaxError" );
60                 }).ajaxSuccess(function(){
61                         ok( true, "ajaxSuccess" );
62                 });
63
64                 jQuery.ajax( url("data/name.html") , {
65                         beforeSend: function(){ ok(true, "beforeSend"); },
66                         success: function(){ ok(true, "success"); },
67                         error: function(){ ok(false, "error"); },
68                         complete: function(){ ok(true, "complete"); }
69                 });
70         }, 13);
71 });
72
73 test("jQuery.ajax() - success callbacks (late binding)", function() {
74         expect( 8 );
75
76         jQuery.ajaxSetup({ timeout: 0 });
77
78         stop();
79
80         setTimeout(function(){
81                 jQuery('#foo').ajaxStart(function(){
82                         ok( true, "ajaxStart" );
83                 }).ajaxStop(function(){
84                         ok( true, "ajaxStop" );
85                         start();
86                 }).ajaxSend(function(){
87                         ok( true, "ajaxSend" );
88                 }).ajaxComplete(function(){
89                         ok( true, "ajaxComplete" );
90                 }).ajaxError(function(){
91                         ok( false, "ajaxError" );
92                 }).ajaxSuccess(function(){
93                         ok( true, "ajaxSuccess" );
94                 });
95
96                 jQuery.ajax({
97                         url: url("data/name.html"),
98                         beforeSend: function(){ ok(true, "beforeSend"); }
99                 })
100                         .complete(function(){ ok(true, "complete"); })
101                         .success(function(){ ok(true, "success"); })
102                         .error(function(){ ok(false, "error"); });
103         }, 13);
104 });
105
106 test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
107         expect( 8 );
108
109         jQuery.ajaxSetup({ timeout: 0 });
110
111         stop();
112
113         setTimeout(function(){
114                 jQuery('#foo').ajaxStart(function(){
115                         ok( true, "ajaxStart" );
116                 }).ajaxStop(function(){
117                         ok( true, "ajaxStop" );
118                 }).ajaxSend(function(){
119                         ok( true, "ajaxSend" );
120                 }).ajaxComplete(function(){
121                         ok( true, "ajaxComplete" );
122                 }).ajaxError(function(){
123                         ok( false, "ajaxError" );
124                 }).ajaxSuccess(function(){
125                         ok( true, "ajaxSuccess" );
126                 });
127
128                 jQuery.ajax({
129                         url: url("data/name.html"),
130                         beforeSend: function(){ ok(true, "beforeSend"); },
131                         complete: function(xhr) {
132                                 xhr
133                                 .complete(function(){ ok(true, "complete"); })
134                                 .success(function(){ ok(true, "success"); })
135                                 .error(function(){ ok(false, "error"); })
136                                 .complete(function(){ start(); });
137                         }
138                 });
139         }, 13);
140 });
141
142 test("jQuery.ajax() - success callbacks (very late binding)", function() {
143         expect( 8 );
144
145         jQuery.ajaxSetup({ timeout: 0 });
146
147         stop();
148
149         setTimeout(function(){
150                 jQuery('#foo').ajaxStart(function(){
151                         ok( true, "ajaxStart" );
152                 }).ajaxStop(function(){
153                         ok( true, "ajaxStop" );
154                 }).ajaxSend(function(){
155                         ok( true, "ajaxSend" );
156                 }).ajaxComplete(function(){
157                         ok( true, "ajaxComplete" );
158                 }).ajaxError(function(){
159                         ok( false, "ajaxError" );
160                 }).ajaxSuccess(function(){
161                         ok( true, "ajaxSuccess" );
162                 });
163
164                 jQuery.ajax({
165                         url: url("data/name.html"),
166                         beforeSend: function(){ ok(true, "beforeSend"); },
167                         complete: function(xhr) {
168                                 setTimeout (function() {
169                                         xhr
170                                         .complete(function(){ ok(true, "complete"); })
171                                         .success(function(){ ok(true, "success"); })
172                                         .error(function(){ ok(false, "error"); })
173                                         .complete(function(){ start(); });
174                                 },100);
175                         }
176                 });
177         }, 13);
178 });
179
180 test("jQuery.ajax() - success callbacks (order)", function() {
181         expect( 1 );
182
183         jQuery.ajaxSetup({ timeout: 0 });
184
185         stop();
186
187         var testString = "";
188
189         setTimeout(function(){
190                 jQuery.ajax({
191                         url: url("data/name.html"),
192                         success: function( _1 , _2 , xhr ) {
193                                 xhr.success(function() {
194                                         xhr.success(function() {
195                                                 testString += "E";
196                                         });
197                                         testString += "D";
198                                 });
199                                 testString += "A";
200                         },
201                         complete: function() {
202                                 strictEqual(testString, "ABCDE", "Proper order");
203                                 start();
204                         }
205                 }).success(function() {
206                         testString += "B";
207                 }).success(function() {
208                         testString += "C";
209                 });
210         }, 13);
211 });
212
213 test("jQuery.ajax() - error callbacks", function() {
214         expect( 8 );
215         stop();
216
217         jQuery('#foo').ajaxStart(function(){
218                 ok( true, "ajaxStart" );
219         }).ajaxStop(function(){
220                 ok( true, "ajaxStop" );
221                 start();
222         }).ajaxSend(function(){
223                 ok( true, "ajaxSend" );
224         }).ajaxComplete(function(){
225                 ok( true, "ajaxComplete" );
226         }).ajaxError(function(){
227                 ok( true, "ajaxError" );
228         }).ajaxSuccess(function(){
229                 ok( false, "ajaxSuccess" );
230         });
231
232         jQuery.ajaxSetup({ timeout: 500 });
233
234         jQuery.ajax({
235                 url: url("data/name.php?wait=5"),
236                 beforeSend: function(){ ok(true, "beforeSend"); },
237                 success: function(){ ok(false, "success"); },
238                 error: function(){ ok(true, "error"); },
239                 complete: function(){ ok(true, "complete"); }
240         });
241 });
242
243 test( "jQuery.ajax - multiple method signatures introduced in 1.5 ( #8107)", function() {
244
245         expect( 4 );
246
247         stop();
248
249         jQuery.when(
250                 jQuery.ajax().success(function() { ok( true, 'With no arguments' ); }),
251                 jQuery.ajax('data/name.html').success(function() { ok( true, 'With only string URL argument' ); }),
252                 jQuery.ajax('data/name.html', {} ).success(function() { ok( true, 'With string URL param and map' ); }),
253                 jQuery.ajax({ url: 'data/name.html'} ).success(function() { ok( true, 'With only map' ); })
254         ).then( start, start );
255
256 });
257
258 test("jQuery.ajax() - textStatus and errorThrown values", function() {
259
260         var nb = 2;
261
262         expect( 2 * nb );
263         stop();
264
265         function startN() {
266                 if ( !( --nb ) ) {
267                         start();
268                 }
269         }
270
271         /*
272         Safari 3.x returns "OK" instead of "Not Found"
273         Safari 4.x doesn't have this issue so the test should be re-instated once
274         we drop support for 3.x
275
276         jQuery.ajax({
277                 url: url("data/nonExistingURL"),
278                 error: function( _ , textStatus , errorThrown ){
279                         strictEqual( textStatus, "error", "textStatus is 'error' for 404" );
280                         strictEqual( errorThrown, "Not Found", "errorThrown is 'Not Found' for 404");
281                         startN();
282                 }
283         });
284         */
285
286         jQuery.ajax({
287                 url: url("data/name.php?wait=5"),
288                 error: function( _ , textStatus , errorThrown ){
289                         strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
290                         strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort");
291                         startN();
292                 }
293         }).abort();
294
295         jQuery.ajax({
296                 url: url("data/name.php?wait=5"),
297                 error: function( _ , textStatus , errorThrown ){
298                         strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
299                         strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')");
300                         startN();
301                 }
302         }).abort( "mystatus" );
303 });
304
305 test("jQuery.ajax() - responseText on error", function() {
306
307         expect( 1 );
308
309         stop();
310
311         jQuery.ajax({
312                 url: url("data/errorWithText.php"),
313                 error: function(xhr) {
314                         strictEqual( xhr.responseText , "plain text message" , "Test jqXHR.responseText is filled for HTTP errors" );
315                 },
316                 complete: function() {
317                         start();
318                 }
319         });
320 });
321
322 test(".ajax() - retry with jQuery.ajax( this )", function() {
323
324         expect( 1 );
325
326         stop();
327
328         var firstTime = 1;
329
330         jQuery.ajax({
331                 url: url("data/errorWithText.php"),
332                 error: function() {
333                         if ( firstTime ) {
334                                 firstTime = 0;
335                                 jQuery.ajax( this );
336                         } else {
337                                 ok( true , "Test retrying with jQuery.ajax(this) works" );
338                                 start();
339                         }
340                 }
341         });
342
343 });
344
345 test(".ajax() - headers" , function() {
346
347         expect( 2 );
348
349         stop();
350
351         var requestHeaders = {
352                 siMPle: "value",
353                 "SometHing-elsE": "other value",
354                 OthEr: "something else"
355                 },
356                 list = [],
357                 i;
358
359         for( i in requestHeaders ) {
360                 list.push( i );
361         }
362
363         jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
364                 headers: requestHeaders,
365                 success: function( data , _ , xhr ) {
366                         var tmp = [];
367                         for ( i in requestHeaders ) {
368                                 tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
369                         }
370                         tmp = tmp.join( "" );
371
372                         equals( data , tmp , "Headers were sent" );
373                         equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
374                         start();
375                 },
376                 error: function(){ ok(false, "error"); }
377         });
378
379 });
380
381 test(".ajax() - Accept header" , function() {
382
383         expect( 1 );
384
385         stop();
386
387         jQuery.ajax(url("data/headers.php?keys=accept"), {
388                 headers: {
389                         Accept: "very wrong accept value"
390                 },
391                 beforeSend: function( xhr ) {
392                         xhr.setRequestHeader( "Accept", "*/*" );
393                 },
394                 success: function( data ) {
395                         strictEqual( data , "accept: */*\n" , "Test Accept header is set to last value provided" );
396                         start();
397                 },
398                 error: function(){ ok(false, "error"); }
399         });
400
401 });
402
403 test(".ajax() - contentType" , function() {
404
405         expect( 2 );
406
407         stop();
408
409         var count = 2;
410
411         function restart() {
412                 if ( ! --count ) {
413                         start();
414                 }
415         }
416
417         jQuery.ajax(url("data/headers.php?keys=content-type" ), {
418                 contentType: "test",
419                 success: function( data ) {
420                         strictEqual( data , "content-type: test\n" , "Test content-type is sent when options.contentType is set" );
421                 },
422                 complete: function() {
423                         restart();
424                 }
425         });
426
427         jQuery.ajax(url("data/headers.php?keys=content-type" ), {
428                 contentType: false,
429                 success: function( data ) {
430                         strictEqual( data , "content-type: \n" , "Test content-type is not sent when options.contentType===false" );
431                 },
432                 complete: function() {
433                         restart();
434                 }
435         });
436
437 });
438
439 test(".ajax() - protocol-less urls", function() {
440         expect(1);
441
442         jQuery.ajax({
443                 url: "//somedomain.com",
444                 beforeSend: function( xhr, settings ) {
445                         equals(settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added.");
446                         return false;
447                 }
448         });
449 });
450
451 test(".ajax() - hash", function() {
452         expect(3);
453
454         jQuery.ajax({
455                 url: "data/name.html#foo",
456                 beforeSend: function( xhr, settings ) {
457                         equals(settings.url, "data/name.html", "Make sure that the URL is trimmed.");
458                         return false;
459                 }
460         });
461
462         jQuery.ajax({
463                 url: "data/name.html?abc#foo",
464                 beforeSend: function( xhr, settings ) {
465                 equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
466                         return false;
467                 }
468         });
469
470         jQuery.ajax({
471                 url: "data/name.html?abc#foo",
472                 data: { "test": 123 },
473                 beforeSend: function( xhr, settings ) {
474                         equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed.");
475                         return false;
476                 }
477         });
478 });
479
480 test("jQuery ajax - cross-domain detection", function() {
481
482         expect( 4 );
483
484         var loc = document.location,
485                 otherPort = loc.port === 666 ? 667 : 666,
486                 otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
487
488         jQuery.ajax({
489                 dataType: "jsonp",
490                 url: otherProtocol + "//" + loc.host,
491                 beforeSend: function( _ , s ) {
492                         ok( s.crossDomain , "Test different protocols are detected as cross-domain" );
493                         return false;
494                 }
495         });
496
497         jQuery.ajax({
498                 dataType: "jsonp",
499                 url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
500                 beforeSend: function( _ , s ) {
501                         ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
502                         return false;
503                 }
504         });
505
506         jQuery.ajax({
507                 dataType: "jsonp",
508                 url: loc.protocol + "//" + loc.hostname + ":" + otherPort,
509                 beforeSend: function( _ , s ) {
510                         ok( s.crossDomain , "Test different ports are detected as cross-domain" );
511                         return false;
512                 }
513         });
514
515         jQuery.ajax({
516                 dataType: "jsonp",
517                 url: loc.protocol + "//" + loc.host,
518                 crossDomain: true,
519                 beforeSend: function( _ , s ) {
520                         ok( s.crossDomain , "Test forced crossDomain is detected as cross-domain" );
521                         return false;
522                 }
523         });
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(25);
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         // #7945
954         equals( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
955
956         equals( jQuery.param(jQuery("#form :input")), "action=Test&text2=Test&radio1=on&radio2=on&check=on&=on&hidden=&foo%5Bbar%5D=&name=name&search=search&button=&=foobar&select1=&select2=3&select3=1&select4=1&select5=3", "Make sure jQuery objects are properly serialized");
957
958         jQuery.ajaxSetup({ traditional: true });
959
960         var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
961         equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
962
963         params = {someName: [1, 2, 3], regularThing: "blah" };
964         equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
965
966         params = {foo: ['a', 'b', 'c']};
967         equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
968
969         params = {"foo[]":["baz", 42, "All your base are belong to us"]};
970         equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
971
972         params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
973         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" );
974
975         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?" };
976         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" );
977
978         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 ] };
979         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)" );
980
981         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?" };
982         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" );
983
984         params = { param1: null };
985         equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
986
987         params = {'test': {'length': 3, 'foo': 'bar'} };
988         equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
989 });
990
991 test("synchronous request", function() {
992         expect(1);
993         ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );
994 });
995
996 test("synchronous request with callbacks", function() {
997         expect(2);
998         var result;
999         jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } });
1000         ok( /^{ "data"/.test( result ), "check returned text" );
1001 });
1002
1003 test("pass-through request object", function() {
1004         expect(8);
1005         stop();
1006
1007         var target = "data/name.html";
1008         var successCount = 0;
1009         var errorCount = 0;
1010         var errorEx = "";
1011         var success = function() {
1012                 successCount++;
1013         };
1014         jQuery("#foo").ajaxError(function (e, xml, s, ex) {
1015                 errorCount++;
1016                 errorEx += ": " + xml.status;
1017         });
1018         jQuery("#foo").one('ajaxStop', function () {
1019                 equals(successCount, 5, "Check all ajax calls successful");
1020                 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
1021                 jQuery("#foo").unbind('ajaxError');
1022
1023                 start();
1024         });
1025
1026         ok( jQuery.get(url(target), success), "get" );
1027         ok( jQuery.post(url(target), success), "post" );
1028         ok( jQuery.getScript(url("data/test.js"), success), "script" );
1029         ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
1030         ok( jQuery.ajax({url: url(target), success: success}), "generic" );
1031 });
1032
1033 test("ajax cache", function () {
1034         expect(18);
1035
1036         stop();
1037
1038         var count = 0;
1039
1040         jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
1041                 var re = /_=(.*?)(&|$)/g;
1042                 var oldOne = null;
1043                 for (var i = 0; i < 6; i++) {
1044                         var ret = re.exec(s.url);
1045                         if (!ret) {
1046                                 break;
1047                         }
1048                         oldOne = ret[1];
1049                 }
1050                 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
1051                 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
1052                 if(++count == 6)
1053                         start();
1054         });
1055
1056         ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
1057         ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
1058         ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
1059         ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
1060         ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
1061         ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
1062 });
1063
1064 /*
1065  * Test disabled.
1066  * The assertions expect that the passed-in object will be modified,
1067  * which shouldn't be the case. Fixes #5439.
1068 test("global ajaxSettings", function() {
1069         expect(2);
1070
1071         var tmp = jQuery.extend({}, jQuery.ajaxSettings);
1072         var orig = { url: "data/with_fries.xml" };
1073         var t;
1074
1075         jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
1076
1077         t = jQuery.extend({}, orig);
1078         t.data = {};
1079         jQuery.ajax(t);
1080         ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
1081
1082         t = jQuery.extend({}, orig);
1083         t.data = { zoo: 'a', ping: 'b' };
1084         jQuery.ajax(t);
1085         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' }" );
1086
1087         jQuery.ajaxSettings = tmp;
1088 });
1089 */
1090
1091 test("load(String)", function() {
1092         expect(1);
1093         stop(); // check if load can be called with only url
1094         jQuery('#first').load("data/name.html", start);
1095 });
1096
1097 test("load('url selector')", function() {
1098         expect(1);
1099         stop(); // check if load can be called with only url
1100         jQuery('#first').load("data/test3.html div.user", function(){
1101                 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
1102                 start();
1103         });
1104 });
1105
1106 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
1107         expect(1);
1108         stop();
1109         jQuery.ajaxSetup({ dataType: "json" });
1110         jQuery("#first").ajaxComplete(function (e, xml, s) {
1111                 equals( s.dataType, "html", "Verify the load() dataType was html" );
1112                 jQuery("#first").unbind("ajaxComplete");
1113                 jQuery.ajaxSetup({ dataType: "" });
1114                 start();
1115         });
1116         jQuery('#first').load("data/test3.html");
1117 });
1118
1119 test("load(String, Function) - simple: inject text into DOM", function() {
1120         expect(2);
1121         stop();
1122         jQuery('#first').load(url("data/name.html"), function() {
1123                 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
1124                 start();
1125         });
1126 });
1127
1128 test("load(String, Function) - check scripts", function() {
1129         expect(7);
1130         stop();
1131
1132         var verifyEvaluation = function() {
1133                 equals( foobar, "bar", 'Check if script src was evaluated after load' );
1134                 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
1135
1136                 start();
1137         };
1138         jQuery('#first').load(url('data/test.html'), function() {
1139                 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
1140                 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1141                 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1142                 setTimeout(verifyEvaluation, 600);
1143         });
1144 });
1145
1146 test("load(String, Function) - check file with only a script tag", function() {
1147         expect(3);
1148         stop();
1149
1150         jQuery('#first').load(url('data/test2.html'), function() {
1151                 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1152                 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1153
1154                 start();
1155         });
1156 });
1157
1158 test("load(String, Function) - dataFilter in ajaxSettings", function() {
1159         expect(2);
1160         stop();
1161         jQuery.ajaxSetup({ dataFilter: function() { return "Hello World"; } });
1162         var div = jQuery("<div/>").load(url("data/name.html"), function(responseText) {
1163                 strictEqual( div.html(), "Hello World" , "Test div was filled with filtered data" );
1164                 strictEqual( responseText, "Hello World" , "Test callback receives filtered data" );
1165                 jQuery.ajaxSetup({ dataFilter: 0 });
1166                 start();
1167         });
1168 });
1169
1170 test("load(String, Object, Function)", function() {
1171         expect(2);
1172         stop();
1173
1174         jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
1175                 var $post = jQuery(this).find('#post');
1176                 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
1177                 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
1178                 start();
1179         });
1180 });
1181
1182 test("load(String, String, Function)", function() {
1183         expect(2);
1184         stop();
1185
1186         jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
1187                 var $get = jQuery(this).find('#get');
1188                 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
1189                 equals( $get.find('#bar').text(), 'ok', 'Check if a      of data is passed correctly');
1190                 start();
1191         });
1192 });
1193
1194 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
1195         expect(2);
1196         stop();
1197         jQuery.get(url('data/dashboard.xml'), function(xml) {
1198                 var content = [];
1199                 jQuery('tab', xml).each(function() {
1200                         content.push(jQuery(this).text());
1201                 });
1202                 equals( content[0], 'blabla', 'Check first tab');
1203                 equals( content[1], 'blublu', 'Check second tab');
1204                 start();
1205         });
1206 });
1207
1208 test("jQuery.getScript(String, Function) - with callback", function() {
1209         expect(3);
1210         stop();
1211         jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) {
1212                 equals( foobar, "bar", 'Check if script was evaluated' );
1213                 strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
1214                 setTimeout(start, 100);
1215         });
1216 });
1217
1218 test("jQuery.getScript(String, Function) - no callback", function() {
1219         expect(1);
1220         stop();
1221         jQuery.getScript(url("data/test.js"), function(){
1222                 start();
1223         });
1224 });
1225
1226 jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) {
1227
1228         test("jQuery.ajax() - JSONP, " + label, function() {
1229                 expect(20);
1230
1231                 var count = 0;
1232                 function plus(){ if ( ++count == 18 ) start(); }
1233
1234                 stop();
1235
1236                 jQuery.ajax({
1237                         url: "data/jsonp.php",
1238                         dataType: "jsonp",
1239                         crossDomain: crossDomain,
1240                         success: function(data){
1241                                 ok( data.data, "JSON results returned (GET, no callback)" );
1242                                 plus();
1243                         },
1244                         error: function(data){
1245                                 ok( false, "Ajax error JSON (GET, no callback)" );
1246                                 plus();
1247                         }
1248                 });
1249
1250                 jQuery.ajax({
1251                         url: "data/jsonp.php?callback=?",
1252                         dataType: "jsonp",
1253                         crossDomain: crossDomain,
1254                         success: function(data){
1255                                 ok( data.data, "JSON results returned (GET, url callback)" );
1256                                 plus();
1257                         },
1258                         error: function(data){
1259                                 ok( false, "Ajax error JSON (GET, url callback)" );
1260                                 plus();
1261                         }
1262                 });
1263
1264                 jQuery.ajax({
1265                         url: "data/jsonp.php",
1266                         dataType: "jsonp",
1267                         crossDomain: crossDomain,
1268                         data: "callback=?",
1269                         success: function(data){
1270                                 ok( data.data, "JSON results returned (GET, data callback)" );
1271                                 plus();
1272                         },
1273                         error: function(data){
1274                                 ok( false, "Ajax error JSON (GET, data callback)" );
1275                                 plus();
1276                         }
1277                 });
1278
1279                 jQuery.ajax({
1280                         url: "data/jsonp.php?callback=??",
1281                         dataType: "jsonp",
1282                         crossDomain: crossDomain,
1283                         success: function(data){
1284                                 ok( data.data, "JSON results returned (GET, url context-free callback)" );
1285                                 plus();
1286                         },
1287                         error: function(data){
1288                                 ok( false, "Ajax error JSON (GET, url context-free callback)" );
1289                                 plus();
1290                         }
1291                 });
1292
1293                 jQuery.ajax({
1294                         url: "data/jsonp.php",
1295                         dataType: "jsonp",
1296                         crossDomain: crossDomain,
1297                         data: "callback=??",
1298                         success: function(data){
1299                                 ok( data.data, "JSON results returned (GET, data context-free callback)" );
1300                                 plus();
1301                         },
1302                         error: function(data){
1303                                 ok( false, "Ajax error JSON (GET, data context-free callback)" );
1304                                 plus();
1305                         }
1306                 });
1307
1308                 jQuery.ajax({
1309                         url: "data/jsonp.php/??",
1310                         dataType: "jsonp",
1311                         crossDomain: crossDomain,
1312                         success: function(data){
1313                                 ok( data.data, "JSON results returned (GET, REST-like)" );
1314                                 plus();
1315                         },
1316                         error: function(data){
1317                                 ok( false, "Ajax error JSON (GET, REST-like)" );
1318                                 plus();
1319                         }
1320                 });
1321
1322                 jQuery.ajax({
1323                         url: "data/jsonp.php/???json=1",
1324                         dataType: "jsonp",
1325                         crossDomain: crossDomain,
1326                         success: function(data){
1327                                 strictEqual( jQuery.type(data), "array", "JSON results returned (GET, REST-like with param)" );
1328                                 plus();
1329                         },
1330                         error: function(data){
1331                                 ok( false, "Ajax error JSON (GET, REST-like with param)" );
1332                                 plus();
1333                         }
1334                 });
1335
1336                 jQuery.ajax({
1337                         url: "data/jsonp.php",
1338                         dataType: "jsonp",
1339                         crossDomain: crossDomain,
1340                         jsonp: "callback",
1341                         success: function(data){
1342                                 ok( data.data, "JSON results returned (GET, data obj callback)" );
1343                                 plus();
1344                         },
1345                         error: function(data){
1346                                 ok( false, "Ajax error JSON (GET, data obj callback)" );
1347                                 plus();
1348                         }
1349                 });
1350
1351                 window.jsonpResults = function(data) {
1352                         ok( data.data, "JSON results returned (GET, custom callback function)" );
1353                         window.jsonpResults = undefined;
1354                         plus();
1355                 };
1356
1357                 jQuery.ajax({
1358                         url: "data/jsonp.php",
1359                         dataType: "jsonp",
1360                         crossDomain: crossDomain,
1361                         jsonpCallback: "jsonpResults",
1362                         success: function(data){
1363                                 ok( data.data, "JSON results returned (GET, custom callback name)" );
1364                                 plus();
1365                         },
1366                         error: function(data){
1367                                 ok( false, "Ajax error JSON (GET, custom callback name)" );
1368                                 plus();
1369                         }
1370                 });
1371
1372                 jQuery.ajax({
1373                         url: "data/jsonp.php",
1374                         dataType: "jsonp",
1375                         crossDomain: crossDomain,
1376                         jsonpCallback: "functionToCleanUp",
1377                         success: function(data){
1378                                 ok( data.data, "JSON results returned (GET, custom callback name to be cleaned up)" );
1379                                 strictEqual( window.functionToCleanUp, undefined, "Callback was removed (GET, custom callback name to be cleaned up)" );
1380                                 plus();
1381                                 var xhr;
1382                                 jQuery.ajax({
1383                                         url: "data/jsonp.php",
1384                                         dataType: "jsonp",
1385                                         crossDomain: crossDomain,
1386                                         jsonpCallback: "functionToCleanUp",
1387                                         beforeSend: function( jqXHR ) {
1388                                                 xhr = jqXHR;
1389                                                 return false;
1390                                         }
1391                                 });
1392                                 xhr.error(function() {
1393                                         ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
1394                                         strictEqual( window.functionToCleanUp, undefined, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
1395                                         plus();
1396                                 });
1397                         },
1398                         error: function(data){
1399                                 ok( false, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
1400                                 plus();
1401                         }
1402                 });
1403
1404                 jQuery.ajax({
1405                         type: "POST",
1406                         url: "data/jsonp.php",
1407                         dataType: "jsonp",
1408                         crossDomain: crossDomain,
1409                         success: function(data){
1410                                 ok( data.data, "JSON results returned (POST, no callback)" );
1411                                 plus();
1412                         },
1413                         error: function(data){
1414                                 ok( false, "Ajax error JSON (GET, data obj callback)" );
1415                                 plus();
1416                         }
1417                 });
1418
1419                 jQuery.ajax({
1420                         type: "POST",
1421                         url: "data/jsonp.php",
1422                         data: "callback=?",
1423                         dataType: "jsonp",
1424                         crossDomain: crossDomain,
1425                         success: function(data){
1426                                 ok( data.data, "JSON results returned (POST, data callback)" );
1427                                 plus();
1428                         },
1429                         error: function(data){
1430                                 ok( false, "Ajax error JSON (POST, data callback)" );
1431                                 plus();
1432                         }
1433                 });
1434
1435                 jQuery.ajax({
1436                         type: "POST",
1437                         url: "data/jsonp.php",
1438                         jsonp: "callback",
1439                         dataType: "jsonp",
1440                         crossDomain: crossDomain,
1441                         success: function(data){
1442                                 ok( data.data, "JSON results returned (POST, data obj callback)" );
1443                                 plus();
1444                         },
1445                         error: function(data){
1446                                 ok( false, "Ajax error JSON (POST, data obj callback)" );
1447                                 plus();
1448                         }
1449                 });
1450
1451                 //#7578
1452                 jQuery.ajax({
1453                         url: "data/jsonp.php",
1454                         dataType: "jsonp",
1455                         crossDomain: crossDomain,
1456                         beforeSend: function(){
1457                                 strictEqual( this.cache, false, "cache must be false on JSON request" );
1458                                 plus();
1459                                 return false;
1460                         }
1461                 });
1462
1463                 jQuery.ajax({
1464                         url: "data/jsonp.php?callback=XXX",
1465                         dataType: "jsonp",
1466                         jsonp: false,
1467                         jsonpCallback: "XXX",
1468                         crossDomain: crossDomain,
1469                         beforeSend: function() {
1470                                 ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ) ,
1471                                         "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
1472                                 plus();
1473                         },
1474                         success: function(data){
1475                                 ok( data.data, "JSON results returned (GET, custom callback name with no url manipulation)" );
1476                                 plus();
1477                         },
1478                         error: function(data){
1479                                 ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
1480                                 plus();
1481                         }
1482                 });
1483
1484         });
1485 });
1486
1487 test("jQuery.ajax() - script, Remote", function() {
1488         expect(2);
1489
1490         var base = window.location.href.replace(/[^\/]*$/, "");
1491
1492         stop();
1493
1494         jQuery.ajax({
1495                 url: base + "data/test.js",
1496                 dataType: "script",
1497                 success: function(data){
1498                         ok( foobar, "Script results returned (GET, no callback)" );
1499                         start();
1500                 }
1501         });
1502 });
1503
1504 test("jQuery.ajax() - script, Remote with POST", function() {
1505         expect(3);
1506
1507         var base = window.location.href.replace(/[^\/]*$/, "");
1508
1509         stop();
1510
1511         jQuery.ajax({
1512                 url: base + "data/test.js",
1513                 type: "POST",
1514                 dataType: "script",
1515                 success: function(data, status){
1516                         ok( foobar, "Script results returned (POST, no callback)" );
1517                         equals( status, "success", "Script results returned (POST, no callback)" );
1518                         start();
1519                 },
1520                 error: function(xhr) {
1521                         ok( false, "ajax error, status code: " + xhr.status );
1522                         start();
1523                 }
1524         });
1525 });
1526
1527 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
1528         expect(2);
1529
1530         var base = window.location.href.replace(/[^\/]*$/, "");
1531         base = base.replace(/^.*?\/\//, "//");
1532
1533         stop();
1534
1535         jQuery.ajax({
1536                 url: base + "data/test.js",
1537                 dataType: "script",
1538                 success: function(data){
1539                         ok( foobar, "Script results returned (GET, no callback)" );
1540                         start();
1541                 }
1542         });
1543 });
1544
1545 test("jQuery.ajax() - malformed JSON", function() {
1546         expect(2);
1547
1548         stop();
1549
1550         jQuery.ajax({
1551                 url: "data/badjson.js",
1552                 dataType: "json",
1553                 success: function(){
1554                         ok( false, "Success." );
1555                         start();
1556                 },
1557                 error: function(xhr, msg, detailedMsg) {
1558                         equals( "parsererror", msg, "A parse error occurred." );
1559                         ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" );
1560                         start();
1561                 }
1562         });
1563 });
1564
1565 test("jQuery.ajax() - script by content-type", function() {
1566         expect(2);
1567
1568         stop();
1569
1570         jQuery.when(
1571
1572                 jQuery.ajax({
1573                         url: "data/script.php",
1574                         data: { header: "script" }
1575                 }),
1576
1577                 jQuery.ajax({
1578                         url: "data/script.php",
1579                         data: { header: "ecma" }
1580                 })
1581
1582         ).then( start, start );
1583 });
1584
1585 test("jQuery.ajax() - json by content-type", function() {
1586         expect(5);
1587
1588         stop();
1589
1590         jQuery.ajax({
1591                 url: "data/json.php",
1592                 data: { header: "json", json: "array" },
1593                 success: function( json ) {
1594                         ok( json.length >= 2, "Check length");
1595                         equals( json[0].name, 'John', 'Check JSON: first, name' );
1596                         equals( json[0].age, 21, 'Check JSON: first, age' );
1597                         equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1598                         equals( json[1].age, 25, 'Check JSON: second, age' );
1599                         start();
1600                 }
1601         });
1602 });
1603
1604 test("jQuery.ajax() - json by content-type disabled with options", function() {
1605         expect(6);
1606
1607         stop();
1608
1609         jQuery.ajax({
1610                 url: url("data/json.php"),
1611                 data: { header: "json", json: "array" },
1612                 contents: {
1613                         json: false
1614                 },
1615                 success: function( text ) {
1616                         equals( typeof text , "string" , "json wasn't auto-determined" );
1617                         var json = jQuery.parseJSON( text );
1618                         ok( json.length >= 2, "Check length");
1619                         equals( json[0].name, 'John', 'Check JSON: first, name' );
1620                         equals( json[0].age, 21, 'Check JSON: first, age' );
1621                         equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1622                         equals( json[1].age, 25, 'Check JSON: second, age' );
1623                         start();
1624                 }
1625         });
1626 });
1627
1628 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
1629         expect(5);
1630         stop();
1631         jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
1632           ok( json.length >= 2, "Check length");
1633           equals( json[0].name, 'John', 'Check JSON: first, name' );
1634           equals( json[0].age, 21, 'Check JSON: first, age' );
1635           equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1636           equals( json[1].age, 25, 'Check JSON: second, age' );
1637           start();
1638         });
1639 });
1640
1641 test("jQuery.getJSON(String, Function) - JSON object", function() {
1642         expect(2);
1643         stop();
1644         jQuery.getJSON(url("data/json.php"), function(json) {
1645           if (json && json.data) {
1646                   equals( json.data.lang, 'en', 'Check JSON: lang' );
1647                   equals( json.data.length, 25, 'Check JSON: length' );
1648           }
1649           start();
1650         });
1651 });
1652
1653 test("jQuery.getJSON - Using Native JSON", function() {
1654         expect(2);
1655
1656         var old = window.JSON;
1657         JSON = {
1658                 parse: function(str){
1659                         ok( true, "Verifying that parse method was run" );
1660                         return true;
1661                 }
1662         };
1663
1664         stop();
1665         jQuery.getJSON(url("data/json.php"), function(json) {
1666                 window.JSON = old;
1667                 equals( json, true, "Verifying return value" );
1668                 start();
1669         });
1670 });
1671
1672 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
1673         expect(2);
1674
1675         var base = window.location.href.replace(/[^\/]*$/, "");
1676
1677         stop();
1678         jQuery.getJSON(url(base + "data/json.php"), function(json) {
1679           equals( json.data.lang, 'en', 'Check JSON: lang' );
1680           equals( json.data.length, 25, 'Check JSON: length' );
1681           start();
1682         });
1683 });
1684
1685 test("jQuery.post - data", 3, function() {
1686         stop();
1687
1688         jQuery.when(
1689                 jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) {
1690                         jQuery( 'math', xml ).each( function() {
1691                                 equals( jQuery( 'calculation', this ).text(), '5-2', 'Check for XML' );
1692                                 equals( jQuery( 'result', this ).text(), '3', 'Check for XML' );
1693                         });
1694                 }),
1695
1696                 jQuery.ajax({
1697                         url: url('data/echoData.php'),
1698                         type: "POST",
1699                         data: {
1700                                 'test': {
1701                                         'length': 7,
1702                                                 'foo': 'bar'
1703                                 }
1704                         },
1705                         success: function( data ) {
1706                                 strictEqual( data, 'test%5Blength%5D=7&test%5Bfoo%5D=bar', 'Check if a sub-object with a length param is serialized correctly');
1707                         }
1708                 })
1709         ).then( start, start );
1710
1711 });
1712
1713 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
1714         expect(4);
1715         stop();
1716         var done = 0;
1717
1718         jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
1719           jQuery('math', xml).each(function() {
1720                         equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1721                         equals( jQuery('result', this).text(), '3', 'Check for XML' );
1722                  });
1723           if ( ++done === 2 ) start();
1724         });
1725
1726         jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
1727           jQuery('math', xml).each(function() {
1728                         equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1729                         equals( jQuery('result', this).text(), '3', 'Check for XML' );
1730                  });
1731           if ( ++done === 2 ) start();
1732         });
1733 });
1734
1735 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
1736         stop();
1737
1738         var passed = 0;
1739
1740         jQuery.ajaxSetup({timeout: 1000});
1741
1742         var pass = function() {
1743                 passed++;
1744                 if ( passed == 2 ) {
1745                         ok( true, 'Check local and global callbacks after timeout' );
1746                         jQuery('#main').unbind("ajaxError");
1747                         start();
1748                 }
1749         };
1750
1751         var fail = function(a,b,c) {
1752                 ok( false, 'Check for timeout failed ' + a + ' ' + b );
1753                 start();
1754         };
1755
1756         jQuery('#main').ajaxError(pass);
1757
1758         jQuery.ajax({
1759           type: "GET",
1760           url: url("data/name.php?wait=5"),
1761           error: pass,
1762           success: fail
1763         });
1764
1765         // reset timeout
1766         jQuery.ajaxSetup({timeout: 0});
1767 });
1768
1769 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
1770         stop();
1771         jQuery.ajaxSetup({timeout: 50});
1772
1773         jQuery.ajax({
1774           type: "GET",
1775           timeout: 15000,
1776           url: url("data/name.php?wait=1"),
1777           error: function() {
1778                    ok( false, 'Check for local timeout failed' );
1779                    start();
1780           },
1781           success: function() {
1782                 ok( true, 'Check for local timeout' );
1783                 start();
1784           }
1785         });
1786
1787         // reset timeout
1788         jQuery.ajaxSetup({timeout: 0});
1789 });
1790
1791 test("jQuery.ajax - simple get", function() {
1792         expect(1);
1793         stop();
1794         jQuery.ajax({
1795           type: "GET",
1796           url: url("data/name.php?name=foo"),
1797           success: function(msg){
1798                 equals( msg, 'bar', 'Check for GET' );
1799                 start();
1800           }
1801         });
1802 });
1803
1804 test("jQuery.ajax - simple post", function() {
1805         expect(1);
1806         stop();
1807         jQuery.ajax({
1808           type: "POST",
1809           url: url("data/name.php"),
1810           data: "name=peter",
1811           success: function(msg){
1812                 equals( msg, 'pan', 'Check for POST' );
1813                 start();
1814           }
1815         });
1816 });
1817
1818 test("ajaxSetup()", function() {
1819         expect(1);
1820         stop();
1821         jQuery.ajaxSetup({
1822                 url: url("data/name.php?name=foo"),
1823                 success: function(msg){
1824                         equals( msg, 'bar', 'Check for GET' );
1825                         start();
1826                 }
1827         });
1828         jQuery.ajax();
1829 });
1830
1831 /*
1832 test("custom timeout does not set error message when timeout occurs, see #970", function() {
1833         stop();
1834         jQuery.ajax({
1835                 url: "data/name.php?wait=1",
1836                 timeout: 500,
1837                 error: function(request, status) {
1838                         ok( status != null, "status shouldn't be null in error handler" );
1839                         equals( "timeout", status );
1840                         start();
1841                 }
1842         });
1843 });
1844 */
1845
1846 test("data option: evaluate function values (#2806)", function() {
1847         stop();
1848         jQuery.ajax({
1849                 url: "data/echoQuery.php",
1850                 data: {
1851                         key: function() {
1852                                 return "value";
1853                         }
1854                 },
1855                 success: function(result) {
1856                         equals( result, "key=value" );
1857                         start();
1858                 }
1859         });
1860 });
1861
1862 test("data option: empty bodies for non-GET requests", function() {
1863         stop();
1864         jQuery.ajax({
1865                 url: "data/echoData.php",
1866                 data: undefined,
1867                 type: "post",
1868                 success: function(result) {
1869                         equals( result, "" );
1870                         start();
1871                 }
1872         });
1873 });
1874
1875 var ifModifiedNow = new Date();
1876
1877 jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ) {
1878
1879         test("jQuery.ajax - If-Modified-Since support" + label, function() {
1880                 expect( 3 );
1881
1882                 stop();
1883
1884                 var url = "data/if_modified_since.php?ts=" + ifModifiedNow++;
1885
1886                 jQuery.ajax({
1887                         url: url,
1888                         ifModified: true,
1889                         cache: cache,
1890                         success: function(data, status) {
1891                                 equals(status, "success" );
1892
1893                                 jQuery.ajax({
1894                                         url: url,
1895                                         ifModified: true,
1896                                         cache: cache,
1897                                         success: function(data, status) {
1898                                                 if ( data === "FAIL" ) {
1899                                                         ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1900                                                         ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1901                                                 } else {
1902                                                         equals(status, "notmodified");
1903                                                         ok(data == null, "response body should be empty");
1904                                                 }
1905                                                 start();
1906                                 },
1907                                         error: function() {
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                                                 ok(jQuery.browser.opera, "error");
1913                                                 start();
1914                                         }
1915                                 });
1916                         },
1917                         error: function() {
1918                                 equals(false, "error");
1919                                 // Do this because opera simply refuses to implement 304 handling :(
1920                                 // A feature-driven way of detecting this would be appreciated
1921                                 // See: http://gist.github.com/599419
1922                                 ok(jQuery.browser.opera, "error");
1923                                 start();
1924                         }
1925                 });
1926         });
1927
1928         test("jQuery.ajax - Etag support" + label, function() {
1929                 expect( 3 );
1930
1931                 stop();
1932
1933                 var url = "data/etag.php?ts=" + ifModifiedNow++;
1934
1935                 jQuery.ajax({
1936                         url: url,
1937                         ifModified: true,
1938                         cache: cache,
1939                         success: function(data, status) {
1940                                 equals(status, "success" );
1941
1942                                 jQuery.ajax({
1943                                         url: url,
1944                                         ifModified: true,
1945                                         cache: cache,
1946                                         success: function(data, status) {
1947                                                 if ( data === "FAIL" ) {
1948                                                         ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1949                                                         ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1950                                                 } else {
1951                                                         equals(status, "notmodified");
1952                                                         ok(data == null, "response body should be empty");
1953                                                 }
1954                                                 start();
1955                                 },
1956                                 error: function() {
1957                                                 // Do this because opera simply refuses to implement 304 handling :(
1958                                                 // A feature-driven way of detecting this would be appreciated
1959                                                 // See: http://gist.github.com/599419
1960                                                 ok(jQuery.browser.opera, "error");
1961                                                 ok(jQuery.browser.opera, "error");
1962                                                 start();
1963                                         }
1964                                 });
1965                         },
1966                         error: function() {
1967                                 // Do this because opera simply refuses to implement 304 handling :(
1968                                 // A feature-driven way of detecting this would be appreciated
1969                                 // See: http://gist.github.com/599419
1970                                 ok(jQuery.browser.opera, "error");
1971                                 start();
1972                         }
1973                 });
1974         });
1975 });
1976
1977 test("jQuery ajax - failing cross-domain", function() {
1978
1979         expect( 2 );
1980
1981         stop();
1982
1983         var i = 2;
1984
1985         jQuery.ajax({
1986                 url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
1987                 success: function(){ ok( false , "success" ); },
1988                 error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
1989                 complete: function() { if ( ! --i ) start(); }
1990         });
1991
1992         jQuery.ajax({
1993                 url: 'http://www.google.com',
1994                 success: function(){ ok( false , "success" ); },
1995                 error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
1996                 complete: function() { if ( ! --i ) start(); }
1997         });
1998
1999 });
2000
2001 test("jQuery ajax - atom+xml", function() {
2002
2003         stop();
2004
2005         jQuery.ajax({
2006                 url: url( 'data/atom+xml.php' ),
2007                 success: function(){ ok( true , "success" ); },
2008                 error: function(){ ok( false , "error" ); },
2009                 complete: function() { start(); }
2010         });
2011
2012 });
2013
2014 test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
2015         var success = false;
2016         try {
2017                 var xhr = jQuery.ajax({ url: window.location });
2018                 success = true;
2019                 xhr.abort();
2020         } catch (e) {}
2021
2022         ok( success, "document.location did not generate exception" );
2023 });
2024
2025 test( "jQuery.ajax - statusCode" , function() {
2026
2027         var count = 12;
2028
2029         expect( 20 );
2030         stop();
2031
2032         function countComplete() {
2033                 if ( ! --count ) {
2034                         start();
2035                 }
2036         }
2037
2038         function createStatusCodes( name , isSuccess ) {
2039                 name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
2040                 return {
2041                         200: function() {
2042                                 ok( isSuccess , name );
2043                         },
2044                         404: function() {
2045                                 ok( ! isSuccess , name );
2046                         }
2047                 };
2048         }
2049
2050         jQuery.each( {
2051                 "data/name.html": true,
2052                 "data/someFileThatDoesNotExist.html": false
2053         } , function( uri , isSuccess ) {
2054
2055                 jQuery.ajax( url( uri ) , {
2056                         statusCode: createStatusCodes( "in options" , isSuccess ),
2057                         complete: countComplete
2058                 });
2059
2060                 jQuery.ajax( url( uri ) , {
2061                         complete: countComplete
2062                 }).statusCode( createStatusCodes( "immediately with method" , isSuccess ) );
2063
2064                 jQuery.ajax( url( uri ) , {
2065                         complete: function(jqXHR) {
2066                                 jqXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) );
2067                                 countComplete();
2068                         }
2069                 });
2070
2071                 jQuery.ajax( url( uri ) , {
2072                         complete: function(jqXHR) {
2073                                 setTimeout( function() {
2074                                         jqXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) );
2075                                         countComplete();
2076                                 } , 100 );
2077                         }
2078                 });
2079
2080                 jQuery.ajax( url( uri ) , {
2081                         statusCode: createStatusCodes( "all (options)" , isSuccess ),
2082                         complete: function(jqXHR) {
2083                                 jqXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) );
2084                                 setTimeout( function() {
2085                                         jqXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) );
2086                                         countComplete();
2087                                 } , 100 );
2088                         }
2089                 }).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) );
2090
2091                 var testString = "";
2092
2093                 jQuery.ajax( url( uri ), {
2094                         success: function( a , b , jqXHR ) {
2095                                 ok( isSuccess , "success" );
2096                                 var statusCode = {};
2097                                 statusCode[ jqXHR.status ] = function() {
2098                                         testString += "B";
2099                                 };
2100                                 jqXHR.statusCode( statusCode );
2101                                 testString += "A";
2102                         },
2103                         error: function( jqXHR ) {
2104                                 ok( ! isSuccess , "error" );
2105                                 var statusCode = {};
2106                                 statusCode[ jqXHR.status ] = function() {
2107                                         testString += "B";
2108                                 };
2109                                 jqXHR.statusCode( statusCode );
2110                                 testString += "A";
2111                         },
2112                         complete: function() {
2113                                 strictEqual( testString , "AB" , "Test statusCode callbacks are ordered like " +
2114                                                 ( isSuccess ? "success" :  "error" ) + " callbacks" );
2115                                 countComplete();
2116                         }
2117                 } );
2118
2119         });
2120 });
2121
2122 test("jQuery.ajax - transitive conversions", function() {
2123
2124         expect( 8 );
2125
2126         stop();
2127
2128         jQuery.when(
2129
2130                 jQuery.ajax( url("data/json.php") , {
2131                         converters: {
2132                                 "json myJson": function( data ) {
2133                                         ok( true , "converter called" );
2134                                         return data;
2135                                 }
2136                         },
2137                         dataType: "myJson",
2138                         success: function() {
2139                                 ok( true , "Transitive conversion worked" );
2140                                 strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" );
2141                                 strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType" );
2142                         }
2143                 }),
2144
2145                 jQuery.ajax( url("data/json.php") , {
2146                         converters: {
2147                                 "json myJson": function( data ) {
2148                                         ok( true , "converter called (*)" );
2149                                         return data;
2150                                 }
2151                         },
2152                         contents: false, /* headers are wrong so we ignore them */
2153                         dataType: "* myJson",
2154                         success: function() {
2155                                 ok( true , "Transitive conversion worked (*)" );
2156                                 strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" );
2157                                 strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType (*)" );
2158                         }
2159                 })
2160
2161         ).then( start , start );
2162
2163 });
2164
2165 test("jQuery.ajax - abort in prefilter", function() {
2166
2167         expect( 1 );
2168
2169         jQuery.ajaxPrefilter(function( options, _, jqXHR ) {
2170                 if ( options.abortInPrefilter ) {
2171                         jqXHR.abort();
2172                 }
2173         });
2174
2175         strictEqual( jQuery.ajax({
2176                 abortInPrefilter: true,
2177                 error: function() {
2178                         ok( false, "error callback called" );
2179                 }
2180         }), false, "Request was properly aborted early by the prefilter" );
2181
2182 });
2183
2184 test("jQuery.ajax - active counter", function() {
2185     ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
2186 });
2187
2188 }
2189
2190 //}