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