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