Exaggerate the times for the localtimeout ajax test.
[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         setTimeout(function(){
18                 jQuery('#foo').ajaxStart(function(){
19                         ok( true, "ajaxStart" );
20                 }).ajaxStop(function(){
21                         ok( true, "ajaxStop" );
22                         start();
23                 }).ajaxSend(function(){
24                         ok( true, "ajaxSend" );
25                 }).ajaxComplete(function(){
26                         ok( true, "ajaxComplete" );
27                 }).ajaxError(function(){
28                         ok( false, "ajaxError" );
29                 }).ajaxSuccess(function(){
30                         ok( true, "ajaxSuccess" );
31                 });
32
33                 jQuery.ajax({
34                         url: url("data/name.html"),
35                         beforeSend: function(){ ok(true, "beforeSend"); },
36                         success: function(){ ok(true, "success"); },
37                         error: function(){ ok(false, "error"); },
38                         complete: function(){ ok(true, "complete"); }
39                 });
40         }, 13);
41 });
42
43 test("jQuery.ajax() - error callbacks", function() {
44         expect( 8 );
45         stop();
46
47         jQuery('#foo').ajaxStart(function(){
48                 ok( true, "ajaxStart" );
49         }).ajaxStop(function(){
50                 ok( true, "ajaxStop" );
51                 start();
52         }).ajaxSend(function(){
53                 ok( true, "ajaxSend" );
54         }).ajaxComplete(function(){
55                 ok( true, "ajaxComplete" );
56         }).ajaxError(function(){
57                 ok( true, "ajaxError" );
58         }).ajaxSuccess(function(){
59                 ok( false, "ajaxSuccess" );
60         });
61
62         jQuery.ajaxSetup({ timeout: 500 });
63
64         jQuery.ajax({
65                 url: url("data/name.php?wait=5"),
66                 beforeSend: function(){ ok(true, "beforeSend"); },
67                 success: function(){ ok(false, "success"); },
68                 error: function(){ ok(true, "error"); },
69                 complete: function(){ ok(true, "complete"); }
70         });
71 });
72
73 test("jQuery.ajax() - disabled globals", function() {
74         expect( 3 );
75         stop();
76
77         jQuery('#foo').ajaxStart(function(){
78                 ok( false, "ajaxStart" );
79         }).ajaxStop(function(){
80                 ok( false, "ajaxStop" );
81         }).ajaxSend(function(){
82                 ok( false, "ajaxSend" );
83         }).ajaxComplete(function(){
84                 ok( false, "ajaxComplete" );
85         }).ajaxError(function(){
86                 ok( false, "ajaxError" );
87         }).ajaxSuccess(function(){
88                 ok( false, "ajaxSuccess" );
89         });
90
91         jQuery.ajax({
92                 global: false,
93                 url: url("data/name.html"),
94                 beforeSend: function(){ ok(true, "beforeSend"); },
95                 success: function(){ ok(true, "success"); },
96                 error: function(){ ok(false, "error"); },
97                 complete: function(){
98                   ok(true, "complete");
99                   setTimeout(function(){ start(); }, 13);
100                 }
101         });
102 });
103
104 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
105         expect(3);
106         stop();
107         jQuery.ajax({
108           url: url("data/with_fries.xml"),
109           dataType: "xml",
110           success: function(resp) {
111                 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
112                 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
113                 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
114                 start();
115           }
116         });
117 });
118
119 test("jQuery.ajax - beforeSend", function() {
120         expect(1);
121         stop();
122
123         var check = false;
124
125         jQuery.ajaxSetup({ timeout: 0 });
126
127         jQuery.ajax({
128                 url: url("data/name.html"),
129                 beforeSend: function(xml) {
130                         check = true;
131                 },
132                 success: function(data) {
133                         ok( check, "check beforeSend was executed" );
134                         start();
135                 }
136         });
137 });
138
139 test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
140         expect(2);
141         var request = jQuery.ajax({
142                 url: url("data/name.html"),
143                 beforeSend: function() {
144                         ok( true, "beforeSend got called, canceling" );
145                         return false;
146                 },
147                 success: function() {
148                         ok( false, "request didn't get canceled" );
149                 },
150                 complete: function() {
151                         ok( false, "request didn't get canceled" );
152                 },
153                 error: function() {
154                         ok( false, "request didn't get canceled" );
155                 }
156         });
157         ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
158 });
159
160 window.foobar = null;
161 window.testFoo = undefined;
162
163 test("jQuery.ajax - dataType html", function() {
164         expect(5);
165         stop();
166
167         var verifyEvaluation = function() {
168                 equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
169                 equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
170
171                 start();
172         };
173
174         jQuery.ajax({
175           dataType: "html",
176           url: url("data/test.html"),
177           success: function(data) {
178                 jQuery("#ap").html(data);
179                 ok( data.match(/^html text/), 'Check content for datatype html' );
180                 setTimeout(verifyEvaluation, 600);
181           }
182         });
183 });
184
185 test("serialize()", function() {
186         expect(6);
187
188         equals( jQuery('#form').serialize(),
189                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2",
190                 'Check form serialization as query string');
191
192         equals( jQuery('#form :input').serialize(),
193                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2",
194                 'Check input serialization as query string');
195
196         equals( jQuery('#testForm').serialize(),
197                 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
198                 'Check form serialization as query string');
199
200         equals( jQuery('#testForm :input').serialize(),
201                 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
202                 'Check input serialization as query string');
203
204         equals( jQuery('#form, #testForm').serialize(),
205                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
206                 'Multiple form serialization as query string');
207
208         equals( jQuery('#form, #testForm :input').serialize(),
209                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
210                 'Mixed form/input serialization as query string');
211 });
212
213 test("jQuery.param()", function() {
214         expect(4);
215         var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
216         equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
217
218         params = {someName: [1, 2, 3], regularThing: "blah" };
219         equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
220
221         params = {"foo[]":["baz", 42, "All your base are belong to us"]};
222         equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
223
224         params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
225         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" );
226 });
227
228 test("synchronous request", function() {
229         expect(1);
230         ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" );
231 });
232
233 test("synchronous request with callbacks", function() {
234         expect(2);
235         var result;
236         jQuery.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } });
237         ok( /^{ "data"/.test( result ), "check returned text" );
238 });
239
240 test("pass-through request object", function() {
241         expect(8);
242         stop();
243
244         var target = "data/name.html";
245         var successCount = 0;
246         var errorCount = 0;
247         var errorEx = "";
248         var success = function() {
249                 successCount++;
250         };
251         jQuery("#foo").ajaxError(function (e, xml, s, ex) {
252                 errorCount++;
253                 errorEx += ": " + xml.status;
254         });
255         jQuery("#foo").one('ajaxStop', function () {
256                 equals(successCount, 5, "Check all ajax calls successful");
257                 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
258                 jQuery("#foo").unbind('ajaxError');
259
260                 start();
261         });
262
263         ok( jQuery.get(url(target), success), "get" );
264         ok( jQuery.post(url(target), success), "post" );
265         ok( jQuery.getScript(url("data/test.js"), success), "script" );
266         ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
267         ok( jQuery.ajax({url: url(target), success: success}), "generic" );
268 });
269
270 test("ajax cache", function () {
271         expect(18);
272         stop();
273
274         var count = 0;
275
276         jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
277                 var re = /_=(.*?)(&|$)/g;
278         var oldOne = null;
279                 for (var i = 0; i < 6; i++) {
280           var ret = re.exec(s.url);
281                         if (!ret) {
282                                 break;
283                         }
284           oldOne = ret[1];
285                 }
286                 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
287                 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
288                 if(++count == 6)
289                         start();
290         });
291
292         ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
293         ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
294         ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
295         ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
296         ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
297         ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
298 });
299
300 test("global ajaxSettings", function() {
301         expect(2);
302
303         var tmp = jQuery.extend({}, jQuery.ajaxSettings);
304         var orig = { url: "data/with_fries.xml" };
305         var t;
306
307         jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
308
309         t = jQuery.extend({}, orig);
310         t.data = {};
311         jQuery.ajax(t);
312         ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
313
314         t = jQuery.extend({}, orig);
315         t.data = { zoo: 'a', ping: 'b' };
316         jQuery.ajax(t);
317         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' }" );
318
319         jQuery.ajaxSettings = tmp;
320 });
321
322 test("load(String)", function() {
323         expect(1);
324         stop(); // check if load can be called with only url
325         jQuery('#first').load("data/name.html", start);
326 });
327
328 test("load('url selector')", function() {
329         expect(1);
330         stop(); // check if load can be called with only url
331         jQuery('#first').load("data/test3.html div.user", function(){
332                 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
333                 start();
334         });
335 });
336
337 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
338         expect(1);
339         stop();
340         jQuery.ajaxSetup({ dataType: "json" });
341         jQuery("#first").ajaxComplete(function (e, xml, s) {
342                 equals( s.dataType, "html", "Verify the load() dataType was html" );
343                 jQuery("#first").unbind("ajaxComplete");
344                 jQuery.ajaxSetup({ dataType: "" });
345                 start();
346         });
347         jQuery('#first').load("data/test3.html");
348 });
349
350 test("load(String, Function) - simple: inject text into DOM", function() {
351         expect(2);
352         stop();
353         jQuery('#first').load(url("data/name.html"), function() {
354                 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
355                 start();
356         });
357 });
358
359 test("load(String, Function) - check scripts", function() {
360         expect(7);
361         stop();
362
363         var verifyEvaluation = function() {
364                 equals( foobar, "bar", 'Check if script src was evaluated after load' );
365                 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
366
367                 start();
368         };
369         jQuery('#first').load(url('data/test.html'), function() {
370                 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
371                 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
372                 equals( testFoo, "foo", 'Check if script was evaluated after load' );
373                 setTimeout(verifyEvaluation, 600);
374         });
375 });
376
377 test("load(String, Function) - check file with only a script tag", function() {
378         expect(3);
379         stop();
380
381         jQuery('#first').load(url('data/test2.html'), function() {
382                 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
383                 equals( testFoo, "foo", 'Check if script was evaluated after load' );
384
385                 start();
386         });
387 });
388
389 test("load(String, Object, Function)", function() {
390         expect(2);
391         stop();
392
393         jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
394                 var $post = jQuery(this).find('#post');
395                 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
396                 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
397                 start();
398         });
399 });
400
401 test("load(String, String, Function)", function() {
402         expect(2);
403         stop();
404
405         jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
406                 var $get = jQuery(this).find('#get');
407                 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
408                 equals( $get.find('#bar').text(), 'ok', 'Check if a      of data is passed correctly');
409                 start();
410         });
411 });
412
413 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
414         expect(2);
415         stop();
416         jQuery.get(url('data/dashboard.xml'), function(xml) {
417                 var content = [];
418                 jQuery('tab', xml).each(function() {
419                         content.push(jQuery(this).text());
420                 });
421                 equals( content[0], 'blabla', 'Check first tab');
422                 equals( content[1], 'blublu', 'Check second tab');
423                 start();
424         });
425 });
426
427 test("jQuery.getScript(String, Function) - with callback", function() {
428         expect(2);
429         stop();
430         jQuery.getScript(url("data/test.js"), function() {
431                 equals( foobar, "bar", 'Check if script was evaluated' );
432                 setTimeout(start, 100);
433         });
434 });
435
436 test("jQuery.getScript(String, Function) - no callback", function() {
437         expect(1);
438         stop();
439         jQuery.getScript(url("data/test.js"), function(){
440                 start();
441         });
442 });
443
444 test("jQuery.ajax() - JSONP, Local", function() {
445         expect(7);
446
447         var count = 0;
448         function plus(){ if ( ++count == 7 ) start(); }
449
450         stop();
451
452         jQuery.ajax({
453                 url: "data/jsonp.php",
454                 dataType: "jsonp",
455                 success: function(data){
456                         ok( data.data, "JSON results returned (GET, no callback)" );
457                         plus();
458                 },
459                 error: function(data){
460                         ok( false, "Ajax error JSON (GET, no callback)" );
461                         plus();
462                 }
463         });
464
465         jQuery.ajax({
466                 url: "data/jsonp.php?callback=?",
467                 dataType: "jsonp",
468                 success: function(data){
469                         ok( data.data, "JSON results returned (GET, url callback)" );
470                         plus();
471                 },
472                 error: function(data){
473                         ok( false, "Ajax error JSON (GET, url callback)" );
474                         plus();
475                 }
476         });
477
478         jQuery.ajax({
479                 url: "data/jsonp.php",
480                 dataType: "jsonp",
481                 data: "callback=?",
482                 success: function(data){
483                         ok( data.data, "JSON results returned (GET, data callback)" );
484                         plus();
485                 },
486                 error: function(data){
487                         ok( false, "Ajax error JSON (GET, data callback)" );
488                         plus();
489                 }
490         });
491
492         jQuery.ajax({
493                 url: "data/jsonp.php",
494                 dataType: "jsonp",
495                 jsonp: "callback",
496                 success: function(data){
497                         ok( data.data, "JSON results returned (GET, data obj callback)" );
498                         plus();
499                 },
500                 error: function(data){
501                         ok( false, "Ajax error JSON (GET, data obj callback)" );
502                         plus();
503                 }
504         });
505
506         jQuery.ajax({
507                 type: "POST",
508                 url: "data/jsonp.php",
509                 dataType: "jsonp",
510                 success: function(data){
511                         ok( data.data, "JSON results returned (POST, no callback)" );
512                         plus();
513                 },
514                 error: function(data){
515                         ok( false, "Ajax error JSON (GET, data obj callback)" );
516                         plus();
517                 }
518         });
519
520         jQuery.ajax({
521                 type: "POST",
522                 url: "data/jsonp.php",
523                 data: "callback=?",
524                 dataType: "jsonp",
525                 success: function(data){
526                         ok( data.data, "JSON results returned (POST, data callback)" );
527                         plus();
528                 },
529                 error: function(data){
530                         ok( false, "Ajax error JSON (POST, data callback)" );
531                         plus();
532                 }
533         });
534
535         jQuery.ajax({
536                 type: "POST",
537                 url: "data/jsonp.php",
538                 jsonp: "callback",
539                 dataType: "jsonp",
540                 success: function(data){
541                         ok( data.data, "JSON results returned (POST, data obj callback)" );
542                         plus();
543                 },
544                 error: function(data){
545                         ok( false, "Ajax error JSON (POST, data obj callback)" );
546                         plus();
547                 }
548         });
549 });
550
551 test("jQuery.ajax() - JSONP, Remote", function() {
552         expect(4);
553
554         var count = 0;
555         function plus(){ if ( ++count == 4 ) start(); }
556
557         var base = window.location.href.replace(/\?.*$/, "");
558
559         stop();
560
561         jQuery.ajax({
562                 url: base + "data/jsonp.php",
563                 dataType: "jsonp",
564                 success: function(data){
565                         ok( data.data, "JSON results returned (GET, no callback)" );
566                         plus();
567                 },
568                 error: function(data){
569                         ok( false, "Ajax error JSON (GET, no callback)" );
570                         plus();
571                 }
572         });
573
574         jQuery.ajax({
575                 url: base + "data/jsonp.php?callback=?",
576                 dataType: "jsonp",
577                 success: function(data){
578                         ok( data.data, "JSON results returned (GET, url callback)" );
579                         plus();
580                 },
581                 error: function(data){
582                         ok( false, "Ajax error JSON (GET, url callback)" );
583                         plus();
584                 }
585         });
586
587         jQuery.ajax({
588                 url: base + "data/jsonp.php",
589                 dataType: "jsonp",
590                 data: "callback=?",
591                 success: function(data){
592                         ok( data.data, "JSON results returned (GET, data callback)" );
593                         plus();
594                 },
595                 error: function(data){
596                         ok( false, "Ajax error JSON (GET, data callback)" );
597                         plus();
598                 }
599         });
600
601         jQuery.ajax({
602                 url: base + "data/jsonp.php",
603                 dataType: "jsonp",
604                 jsonp: "callback",
605                 success: function(data){
606                         ok( data.data, "JSON results returned (GET, data obj callback)" );
607                         plus();
608                 },
609                 error: function(data){
610                         ok( false, "Ajax error JSON (GET, data obj callback)" );
611                         plus();
612                 }
613         });
614 });
615
616 test("jQuery.ajax() - script, Remote", function() {
617         expect(2);
618
619         var base = window.location.href.replace(/\?.*$/, "");
620
621         stop();
622
623         jQuery.ajax({
624                 url: base + "data/test.js",
625                 dataType: "script",
626                 success: function(data){
627                         ok( foobar, "Script results returned (GET, no callback)" );
628                         start();
629                 }
630         });
631 });
632
633 test("jQuery.ajax() - script, Remote with POST", function() {
634         expect(3);
635
636         var base = window.location.href.replace(/\?.*$/, "");
637
638         stop();
639
640         jQuery.ajax({
641                 url: base + "data/test.js",
642                 type: "POST",
643                 dataType: "script",
644                 success: function(data, status){
645                         ok( foobar, "Script results returned (POST, no callback)" );
646                         equals( status, "success", "Script results returned (POST, no callback)" );
647                         start();
648                 },
649                 error: function(xhr) {
650                         ok( false, "ajax error, status code: " + xhr.status );
651                         start();
652                 }
653         });
654 });
655
656 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
657         expect(2);
658
659         var base = window.location.href.replace(/\?.*$/, "");
660         base = base.replace(/^.*?\/\//, "//");
661
662         stop();
663
664         jQuery.ajax({
665                 url: base + "data/test.js",
666                 dataType: "script",
667                 success: function(data){
668                         ok( foobar, "Script results returned (GET, no callback)" );
669                         start();
670                 }
671         });
672 });
673
674 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
675         expect(4);
676         stop();
677         jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
678           equals( json[0].name, 'John', 'Check JSON: first, name' );
679           equals( json[0].age, 21, 'Check JSON: first, age' );
680           equals( json[1].name, 'Peter', 'Check JSON: second, name' );
681           equals( json[1].age, 25, 'Check JSON: second, age' );
682           start();
683         });
684 });
685
686 test("jQuery.getJSON(String, Function) - JSON object", function() {
687         expect(2);
688         stop();
689         jQuery.getJSON(url("data/json.php"), function(json) {
690           equals( json.data.lang, 'en', 'Check JSON: lang' );
691           equals( json.data.length, 25, 'Check JSON: length' );
692           start();
693         });
694 });
695
696 test("jQuery.getJSON - Using Native JSON", function() {
697         expect(2);
698         
699         var old = window.JSON;
700         JSON = {
701                 parse: function(str){
702                         ok( true, "Verifying that parse method was run" );
703                         return true;
704                 }
705         };
706
707         stop();
708         jQuery.getJSON(url("data/json.php"), function(json) {
709                 window.JSON = old;
710           equals( json, true, "Verifying return value" );
711           start();
712         });
713 });
714
715 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
716         expect(2);
717
718         var base = window.location.href.replace(/\?.*$/, "");
719
720         stop();
721         jQuery.getJSON(url(base + "data/json.php"), function(json) {
722           equals( json.data.lang, 'en', 'Check JSON: lang' );
723           equals( json.data.length, 25, 'Check JSON: length' );
724           start();
725         });
726 });
727
728 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
729         expect(4);
730         stop();
731         var done = 0;
732
733         jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
734           jQuery('math', xml).each(function() {
735                         equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
736                         equals( jQuery('result', this).text(), '3', 'Check for XML' );
737                  });
738           if ( ++done === 2 ) start();
739         });
740
741         jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
742           jQuery('math', xml).each(function() {
743                         equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
744                         equals( jQuery('result', this).text(), '3', 'Check for XML' );
745                  });
746           if ( ++done === 2 ) start();
747         });
748 });
749
750 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
751         stop();
752
753         var passed = 0;
754
755         jQuery.ajaxSetup({timeout: 1000});
756
757         var pass = function() {
758                 passed++;
759                 if ( passed == 2 ) {
760                         ok( true, 'Check local and global callbacks after timeout' );
761                         jQuery('#main').unbind("ajaxError");
762                         start();
763                 }
764         };
765
766         var fail = function(a,b,c) {
767                 ok( false, 'Check for timeout failed ' + a + ' ' + b );
768                 start();
769         };
770
771         jQuery('#main').ajaxError(pass);
772
773         jQuery.ajax({
774           type: "GET",
775           url: url("data/name.php?wait=5"),
776           error: pass,
777           success: fail
778         });
779
780         // reset timeout
781         jQuery.ajaxSetup({timeout: 0});
782 });
783
784 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
785         stop();
786         jQuery.ajaxSetup({timeout: 50});
787
788         jQuery.ajax({
789           type: "GET",
790           timeout: 15000,
791           url: url("data/name.php?wait=1"),
792           error: function() {
793                    ok( false, 'Check for local timeout failed' );
794                    start();
795           },
796           success: function() {
797                 ok( true, 'Check for local timeout' );
798                 start();
799           }
800         });
801
802         // reset timeout
803         jQuery.ajaxSetup({timeout: 0});
804 });
805
806 test("jQuery.ajax - simple get", function() {
807         expect(1);
808         stop();
809         jQuery.ajax({
810           type: "GET",
811           url: url("data/name.php?name=foo"),
812           success: function(msg){
813                 equals( msg, 'bar', 'Check for GET' );
814                 start();
815           }
816         });
817 });
818
819 test("jQuery.ajax - simple post", function() {
820         expect(1);
821         stop();
822         jQuery.ajax({
823           type: "POST",
824           url: url("data/name.php"),
825           data: "name=peter",
826           success: function(msg){
827                 equals( msg, 'pan', 'Check for POST' );
828                 start();
829           }
830         });
831 });
832
833 test("ajaxSetup()", function() {
834         expect(1);
835         stop();
836         jQuery.ajaxSetup({
837                 url: url("data/name.php?name=foo"),
838                 success: function(msg){
839                         equals( msg, 'bar', 'Check for GET' );
840                         start();
841                 }
842         });
843         jQuery.ajax();
844 });
845
846 /*
847 test("custom timeout does not set error message when timeout occurs, see #970", function() {
848         stop();
849         jQuery.ajax({
850                 url: "data/name.php?wait=1",
851                 timeout: 500,
852                 error: function(request, status) {
853                         ok( status != null, "status shouldn't be null in error handler" );
854                         equals( "timeout", status );
855                         start();
856                 }
857         });
858 });
859 */
860
861 test("data option: evaluate function values (#2806)", function() {
862         stop();
863         jQuery.ajax({
864                 url: "data/echoQuery.php",
865                 data: {
866                         key: function() {
867                                 return "value";
868                         }
869                 },
870                 success: function(result) {
871                         equals( result, "key=value" );
872                         start();
873                 }
874         })
875 });
876
877 test("jQuery.ajax - If-Modified-Since support", function() {
878         expect( 3 );
879
880         stop();
881
882         var url = "data/if_modified_since.php?ts=" + new Date();
883
884         jQuery.ajax({
885                 url: url,
886                 ifModified: true,
887                 success: function(data, status) { 
888                         equals(status, "success");
889                         
890                         jQuery.ajax({
891                                 url: url,
892                                 ifModified: true,
893                                 success: function(data, status) { 
894                                         if ( data === "FAIL" ) {
895                                                 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
896                                                 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
897                                         } else {
898                                                 equals(status, "notmodified");
899                                                 ok(data == null, "response body should be empty")
900                                         }
901                                         start();
902                                 }
903                         });
904                 }
905         });
906 });
907
908 test("jQuery.ajax - Etag support", function() {
909         expect( 3 );
910
911         stop();
912
913         var url = "data/etag.php?ts=" + new Date();
914
915         jQuery.ajax({
916                 url: url,
917                 ifModified: true,
918                 success: function(data, status) { 
919                         equals(status, "success");
920                         
921                         jQuery.ajax({
922                                 url: url,
923                                 ifModified: true,
924                                 success: function(data, status) { 
925                                         if ( data === "FAIL" ) {
926                                                 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
927                                                 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
928                                         } else {
929                                                 equals(status, "notmodified");
930                                                 ok(data == null, "response body should be empty")
931                                         }
932                                         start();
933                                 }
934                         });
935                 }
936         });
937 });
938
939 }
940
941 //}