testrunner: Removing every global variable leaked within (and outside) tests. Some...
[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 test("jQuery.ajax - dataType html", function() {
161         expect(5);
162         stop();
163         
164         jQuery.foobar = null;
165         jQuery.testFoo = undefined;
166
167         var verifyEvaluation = function() {
168           equals( jQuery.testFoo, "foo", 'Check if script was evaluated for datatype html' );
169           equals( jQuery.foobar, "bar", 'Check if script src was evaluated for datatype html' );
170           start();
171         };
172
173         jQuery.ajax({
174           dataType: "html",
175           url: url("data/test.html"),
176           success: function(data) {
177                 jQuery("#ap").html(data);
178             ok( data.match(/^html text/), 'Check content for datatype html' );
179             setTimeout(verifyEvaluation, 600);
180           }
181         });
182 });
183
184 test("serialize()", function() {
185         expect(6);
186         
187         equals( jQuery('#form').serialize(),
188                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
189                 'Check form serialization as query string');
190                 
191         equals( jQuery('#form :input').serialize(),
192                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
193                 'Check input serialization as query string');
194         
195         equals( jQuery('#testForm').serialize(), 
196                 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', 
197                 'Check form serialization as query string');
198                 
199         equals( jQuery('#testForm :input').serialize(), 
200                 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', 
201                 'Check input serialization as query string');
202                 
203         equals( jQuery('#form, #testForm').serialize(),
204                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&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=",
205                 'Multiple form serialization as query string');
206                 
207         equals( jQuery('#form, #testForm :input').serialize(),
208                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&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=",
209                 'Mixed form/input serialization as query string');
210 });
211
212 test("jQuery.param()", function() {
213         expect(4);
214         var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
215         equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
216         
217         params = {someName: [1, 2, 3], regularThing: "blah" };
218         equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
219         
220         params = {"foo[]":["baz", 42, "All your base are belong to us"]};
221         equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
222         
223         params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
224         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" );
225 });
226
227 test("synchronous request", function() {
228         expect(1);
229         ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" );
230 });
231
232 test("synchronous request with callbacks", function() {
233         expect(2);
234         var result;
235         jQuery.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } });
236         ok( /^{ "data"/.test( result ), "check returned text" );
237 });
238
239 test("pass-through request object", function() {
240         expect(8);
241         stop();
242         
243         var target = "data/name.html";
244         var successCount = 0;
245         var errorCount = 0;
246   var errorEx = "";
247         var success = function() {
248                 successCount++;
249         };
250         jQuery("#foo").ajaxError(function (e, xml, s, ex) {
251                 errorCount++;
252     errorEx += ": " + xml.status;
253         });
254         jQuery("#foo").one('ajaxStop', function () {
255                 equals(successCount, 5, "Check all ajax calls successful");
256                 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
257                 jQuery("#foo").unbind('ajaxError');
258                 start();
259         });
260         
261         ok( jQuery.get(url(target), success), "get" );
262         ok( jQuery.post(url(target), success), "post" );
263         ok( jQuery.getScript(url("data/test.js"), success), "script" );
264         ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
265         ok( jQuery.ajax({url: url(target), success: success}), "generic" );
266 });
267
268 test("ajax cache", function () {
269         expect(18);
270         stop();
271         
272         var count = 0;
273
274         jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
275                 var re = /_=(.*?)(&|$)/g;
276     var oldOne = null;
277                 for (var i = 0; i < 6; i++) {
278       var ret = re.exec(s.url);
279                         if (!ret) {
280                                 break;
281                         }
282       oldOne = ret[1];
283                 }
284                 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
285                 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
286                 if(++count == 6)
287                         start();
288         });
289
290         ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
291         ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
292         ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
293         ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
294         ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
295         ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
296 });
297
298 test("global ajaxSettings", function() {
299         expect(2);
300
301         var tmp = jQuery.extend({}, jQuery.ajaxSettings);
302     var orig = { url: "data/with_fries.xml" };
303         var t;
304
305         jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
306
307     t = jQuery.extend({}, orig);
308         t.data = {};
309     jQuery.ajax(t);
310         ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
311
312     t = jQuery.extend({}, orig);
313         t.data = { zoo: 'a', ping: 'b' };
314     jQuery.ajax(t);
315         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' }" );
316         
317         jQuery.ajaxSettings = tmp;
318 });
319
320 test("load(String)", function() {
321         expect(1);
322         stop(); // check if load can be called with only url
323         jQuery('#first').load("data/name.html", start);
324 });
325
326 test("load('url selector')", function() {
327         expect(1);
328         stop(); // check if load can be called with only url
329         jQuery('#first').load("data/test3.html div.user", function(){
330                 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
331                 start();
332         });
333 });
334
335 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
336         expect(1);
337         stop();
338         jQuery.ajaxSetup({ dataType: "json" });
339         jQuery("#first").ajaxComplete(function (e, xml, s) {
340                 equals( s.dataType, "html", "Verify the load() dataType was html" );
341                 jQuery("#first").unbind("ajaxComplete");
342                 jQuery.ajaxSetup({ dataType: "" });
343                 start();
344         });
345         jQuery('#first').load("data/test3.html");
346 });
347
348 test("load(String, Function) - simple: inject text into DOM", function() {
349         expect(2);
350         stop();
351         jQuery('#first').load(url("data/name.html"), function() {
352                 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
353                 start();
354         });
355 });
356
357 test("load(String, Function) - check scripts", function() {
358         expect(7);
359         stop();
360         jQuery.testFoo = undefined;
361         jQuery.foobar = null;
362         var verifyEvaluation = function() {
363                 equals( jQuery.foobar, "bar", 'Check if script src was evaluated after load' );
364                 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
365                 start();
366         };
367         jQuery('#first').load(url('data/test.html'), function() {
368                 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
369                 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
370                 equals( jQuery.testFoo, "foo", 'Check if script was evaluated after load' );
371                 setTimeout(verifyEvaluation, 600);
372         });
373 });
374
375 test("load(String, Function) - check file with only a script tag", function() {
376         expect(3);
377         stop();
378         jQuery.testFoo = undefined;
379         jQuery('#first').load(url('data/test2.html'), function() {
380                 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
381                 equals( jQuery.testFoo, "foo", 'Check if script was evaluated after load' );
382                 start();
383         });
384 });
385
386 test("load(String, Object, Function)", function() {
387         expect(2);
388         stop();
389         
390         jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
391                 var $post = jQuery(this).find('#post');         
392                 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
393                 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
394                 start();
395         });
396 });
397
398 test("load(String, String, Function)", function() {
399         expect(2);
400         stop();
401         
402         jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
403                 var $get = jQuery(this).find('#get');           
404                 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
405                 equals( $get.find('#bar').text(), 'ok', 'Check if a  of data is passed correctly');
406                 start();
407         });
408 });
409
410 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
411         expect(2);
412         stop();
413         jQuery.get(url('data/dashboard.xml'), function(xml) {
414                 var content = [];
415                 jQuery('tab', xml).each(function() {
416                         content.push(jQuery(this).text());
417                 });
418                 equals( content[0], 'blabla', 'Check first tab');
419                 equals( content[1], 'blublu', 'Check second tab');
420                 start();
421         });
422 });
423
424 test("jQuery.getScript(String, Function) - with callback", function() {
425         expect(2);
426         stop();
427         jQuery.foobar = null;
428         jQuery.getScript(url("data/test.js"), function() {
429                 equals( jQuery.foobar, "bar", 'Check if script was evaluated' );
430                 setTimeout(start, 100);
431         });
432 });
433
434 test("jQuery.getScript(String, Function) - no callback", function() {
435         expect(1);
436         stop();
437         jQuery.getScript(url("data/test.js"), start);
438 });
439
440 test("jQuery.ajax() - JSONP, Local", function() {
441         expect(7);
442
443         var count = 0;
444         function plus(){ if ( ++count == 7 ) start(); }
445
446         stop();
447
448         jQuery.ajax({
449                 url: "data/jsonp.php",
450                 dataType: "jsonp",
451                 success: function(data){
452                         ok( data.data, "JSON results returned (GET, no callback)" );
453                         plus();
454                 },
455                 error: function(data){
456                         ok( false, "Ajax error JSON (GET, no callback)" );
457                         plus();
458                 }
459         });
460
461         jQuery.ajax({
462                 url: "data/jsonp.php?callback=?",
463                 dataType: "jsonp",
464                 success: function(data){
465                         ok( data.data, "JSON results returned (GET, url callback)" );
466                         plus();
467                 },
468                 error: function(data){
469                         ok( false, "Ajax error JSON (GET, url callback)" );
470                         plus();
471                 }
472         });
473
474         jQuery.ajax({
475                 url: "data/jsonp.php",
476                 dataType: "jsonp",
477                 data: "callback=?",
478                 success: function(data){
479                         ok( data.data, "JSON results returned (GET, data callback)" );
480                         plus();
481                 },
482                 error: function(data){
483                         ok( false, "Ajax error JSON (GET, data callback)" );
484                         plus();
485                 }
486         });
487
488         jQuery.ajax({
489                 url: "data/jsonp.php",
490                 dataType: "jsonp",
491                 jsonp: "callback",
492                 success: function(data){
493                         ok( data.data, "JSON results returned (GET, data obj callback)" );
494                         plus();
495                 },
496                 error: function(data){
497                         ok( false, "Ajax error JSON (GET, data obj callback)" );
498                         plus();
499                 }
500         });
501
502         jQuery.ajax({
503                 type: "POST",
504                 url: "data/jsonp.php",
505                 dataType: "jsonp",
506                 success: function(data){
507                         ok( data.data, "JSON results returned (POST, no callback)" );
508                         plus();
509                 },
510                 error: function(data){
511                         ok( false, "Ajax error JSON (GET, data obj callback)" );
512                         plus();
513                 }
514         });
515
516         jQuery.ajax({
517                 type: "POST",
518                 url: "data/jsonp.php",
519                 data: "callback=?",
520                 dataType: "jsonp",
521                 success: function(data){
522                         ok( data.data, "JSON results returned (POST, data callback)" );
523                         plus();
524                 },
525                 error: function(data){
526                         ok( false, "Ajax error JSON (POST, data callback)" );
527                         plus();
528                 }
529         });
530
531         jQuery.ajax({
532                 type: "POST",
533                 url: "data/jsonp.php",
534                 jsonp: "callback",
535                 dataType: "jsonp",
536                 success: function(data){
537                         ok( data.data, "JSON results returned (POST, data obj callback)" );
538                         plus();
539                 },
540                 error: function(data){
541                         ok( false, "Ajax error JSON (POST, data obj callback)" );
542                         plus();
543                 }
544         });
545 });
546
547 test("jQuery.ajax() - JSONP, Remote", function() {
548         expect(4);
549
550         var count = 0;
551         function plus(){ if ( ++count == 4 ) start(); }
552
553         var base = window.location.href.replace(/\?.*$/, "");
554
555         stop();
556
557         jQuery.ajax({
558                 url: base + "data/jsonp.php",
559                 dataType: "jsonp",
560                 success: function(data){
561                         ok( data.data, "JSON results returned (GET, no callback)" );
562                         plus();
563                 },
564                 error: function(data){
565                         ok( false, "Ajax error JSON (GET, no callback)" );
566                         plus();
567                 }
568         });
569
570         jQuery.ajax({
571                 url: base + "data/jsonp.php?callback=?",
572                 dataType: "jsonp",
573                 success: function(data){
574                         ok( data.data, "JSON results returned (GET, url callback)" );
575                         plus();
576                 },
577                 error: function(data){
578                         ok( false, "Ajax error JSON (GET, url callback)" );
579                         plus();
580                 }
581         });
582
583         jQuery.ajax({
584                 url: base + "data/jsonp.php",
585                 dataType: "jsonp",
586                 data: "callback=?",
587                 success: function(data){
588                         ok( data.data, "JSON results returned (GET, data callback)" );
589                         plus();
590                 },
591                 error: function(data){
592                         ok( false, "Ajax error JSON (GET, data callback)" );
593                         plus();
594                 }
595         });
596
597         jQuery.ajax({
598                 url: base + "data/jsonp.php",
599                 dataType: "jsonp",
600                 jsonp: "callback",
601                 success: function(data){
602                         ok( data.data, "JSON results returned (GET, data obj callback)" );
603                         plus();
604                 },
605                 error: function(data){
606                         ok( false, "Ajax error JSON (GET, data obj callback)" );
607                         plus();
608                 }
609         });
610 });
611
612 test("jQuery.ajax() - script, Remote", function() {
613         expect(2);
614
615         var base = window.location.href.replace(/\?.*$/, "");
616
617         stop();
618
619         jQuery.foobar = null;
620         jQuery.ajax({
621                 url: base + "data/test.js",
622                 dataType: "script",
623                 success: function(data){
624                         ok( jQuery.foobar, "Script results returned (GET, no callback)" );
625                         start();
626                 }
627         });
628 });
629
630 test("jQuery.ajax() - script, Remote with POST", function() {
631         expect(3);
632
633         var base = window.location.href.replace(/\?.*$/, "");
634
635         stop();
636
637         jQuery.foobar = null;
638         jQuery.ajax({
639                 url: base + "data/test.js",
640                 type: "POST",
641                 dataType: "script",
642                 success: function(data, status){
643                         ok( jQuery.foobar, "Script results returned (GET, no callback)" );
644                         equals( status, "success", "Script results returned (GET, no callback)" );
645                         start();
646                 }
647         });
648 });
649
650 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
651         expect(2);
652
653         var base = window.location.href.replace(/\?.*$/, "");
654         base = base.replace(/^.*?\/\//, "//");
655
656         stop();
657
658         jQuery.foobar = null;
659         jQuery.ajax({
660                 url: base + "data/test.js",
661                 dataType: "script",
662                 success: function(data){
663                         ok( jQuery.foobar, "Script results returned (GET, no callback)" );
664                         start();
665                 }
666         });
667 });
668
669 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
670         expect(4);
671         stop();
672         jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
673           equals( json[0].name, 'John', 'Check JSON: first, name' );
674           equals( json[0].age, 21, 'Check JSON: first, age' );
675           equals( json[1].name, 'Peter', 'Check JSON: second, name' );
676           equals( json[1].age, 25, 'Check JSON: second, age' );
677           start();
678         });
679 });
680
681 test("jQuery.getJSON(String, Function) - JSON object", function() {
682         expect(2);
683         stop();
684         jQuery.getJSON(url("data/json.php"), function(json) {
685           equals( json.data.lang, 'en', 'Check JSON: lang' );
686           equals( json.data.length, 25, 'Check JSON: length' );
687           start();
688         });
689 });
690
691 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
692         expect(2);
693
694         var base = window.location.href.replace(/\?.*$/, "");
695
696         stop();
697         jQuery.getJSON(url(base + "data/json.php"), function(json) {
698           equals( json.data.lang, 'en', 'Check JSON: lang' );
699           equals( json.data.length, 25, 'Check JSON: length' );
700           start();
701         });
702 });
703
704 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
705         expect(4);
706         stop();
707         jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
708           jQuery('math', xml).each(function() {
709                     equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
710                     equals( jQuery('result', this).text(), '3', 'Check for XML' );
711                  });
712         });
713
714         jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
715           jQuery('math', xml).each(function() {
716                     equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
717                     equals( jQuery('result', this).text(), '3', 'Check for XML' );
718                  });
719           start();
720         });
721 });
722
723 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
724         stop();
725         
726         var passed = 0;
727
728         jQuery.ajaxSetup({timeout: 1000});
729         
730         var pass = function() {
731                 passed++;
732                 if ( passed == 2 ) {
733                         ok( true, 'Check local and global callbacks after timeout' );
734                 jQuery('#main').unbind("ajaxError");
735                         start();
736                 }
737         };
738         
739         var fail = function(a,b,c) {
740                 ok( false, 'Check for timeout failed ' + a + ' ' + b );
741                 start();
742         };
743         
744         jQuery('#main').ajaxError(pass);
745         
746         jQuery.ajax({
747           type: "GET",
748           url: url("data/name.php?wait=5"),
749           error: pass,
750           success: fail
751         });
752         
753         // reset timeout
754         jQuery.ajaxSetup({timeout: 0});
755 });
756
757 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
758         stop();
759         jQuery.ajaxSetup({timeout: 50});
760
761         jQuery.ajax({
762           type: "GET",
763           timeout: 5000,
764           url: url("data/name.php?wait=1"),
765           error: function() {
766                    ok( false, 'Check for local timeout failed' );
767                    start();
768           },
769           success: function() {
770             ok( true, 'Check for local timeout' );
771             start();
772           }
773         });
774
775         // reset timeout
776         jQuery.ajaxSetup({timeout: 0});
777 });
778
779 test("jQuery.ajax - simple get", function() {
780         expect(1);
781         stop();
782         jQuery.ajax({
783           type: "GET",
784           url: url("data/name.php?name=foo"),
785           success: function(msg){
786             equals( msg, 'bar', 'Check for GET' );
787             start();
788           }
789         });
790 });
791
792 test("jQuery.ajax - simple post", function() {
793         expect(1);
794         stop();
795         jQuery.ajax({
796           type: "POST",
797           url: url("data/name.php"),
798           data: "name=peter",
799           success: function(msg){
800             equals( msg, 'pan', 'Check for POST' );
801             start();
802           }
803         });
804 });
805
806 test("ajaxSetup()", function() {
807         expect(1);
808         stop();
809         jQuery.ajaxSetup({
810                 url: url("data/name.php?name=foo"),
811                 success: function(msg){
812                 equals( msg, 'bar', 'Check for GET' );
813                         start();
814                 }
815         });
816         jQuery.ajax();
817 });
818
819 /*
820 test("custom timeout does not set error message when timeout occurs, see #970", function() {
821         stop();
822         jQuery.ajax({
823                 url: "data/name.php?wait=1",
824                 timeout: 500,
825                 error: function(request, status) {
826                         ok( status != null, "status shouldn't be null in error handler" );
827                         equals( "timeout", status );
828                         start();
829                 }
830         });
831 });
832 */
833
834 test("data option: evaluate function values (#2806)", function() {
835         stop();
836         jQuery.ajax({
837                 url: "data/echoQuery.php",
838                 data: {
839                         key: function() {
840                                 return "value";
841                         }
842                 },
843                 success: function(result) {
844                         equals( result, "key=value" );
845                         start();
846                 }
847         })
848 });
849
850 }
851
852 //}