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