test runner: the changes are:
[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 var foobar;
161
162 test("jQuery.ajax - dataType html", function() {
163         expect(5);
164         stop();
165         
166         foobar = null;
167         testFoo = undefined;
168
169         var verifyEvaluation = function() {
170           equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
171           equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
172           start();
173         };
174
175         jQuery.ajax({
176           dataType: "html",
177           url: url("data/test.html"),
178           success: function(data) {
179                 jQuery("#ap").html(data);
180             ok( data.match(/^html text/), 'Check content for datatype html' );
181             setTimeout(verifyEvaluation, 600);
182           }
183         });
184 });
185
186 test("serialize()", function() {
187         expect(6);
188         
189         equals( jQuery('#form').serialize(),
190                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
191                 'Check form serialization as query string');
192                 
193         equals( jQuery('#form :input').serialize(),
194                 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
195                 'Check input serialization as query string');
196         
197         equals( jQuery('#testForm').serialize(), 
198                 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', 
199                 'Check form serialization as query string');
200                 
201         equals( jQuery('#testForm :input').serialize(), 
202                 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', 
203                 'Check input serialization as query string');
204                 
205         equals( jQuery('#form, #testForm').serialize(),
206                 "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=",
207                 'Multiple form serialization as query string');
208                 
209         equals( jQuery('#form, #testForm :input').serialize(),
210                 "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=",
211                 'Mixed form/input serialization as query string');
212 });
213
214 test("jQuery.param()", function() {
215         expect(4);
216         var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
217         equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
218         
219         params = {someName: [1, 2, 3], regularThing: "blah" };
220         equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
221         
222         params = {"foo[]":["baz", 42, "All your base are belong to us"]};
223         equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
224         
225         params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
226         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" );
227 });
228
229 test("synchronous request", function() {
230         expect(1);
231         ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" );
232 });
233
234 test("synchronous request with callbacks", function() {
235         expect(2);
236         var result;
237         jQuery.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } });
238         ok( /^{ "data"/.test( result ), "check returned text" );
239 });
240
241 test("pass-through request object", function() {
242         expect(8);
243         stop(true);
244         
245         var target = "data/name.html";
246         var successCount = 0;
247         var errorCount = 0;
248   var errorEx = "";
249         var success = function() {
250                 successCount++;
251         };
252         jQuery("#foo").ajaxError(function (e, xml, s, ex) {
253                 errorCount++;
254     errorEx += ": " + xml.status;
255         });
256         jQuery("#foo").one('ajaxStop', function () {
257                 equals(successCount, 5, "Check all ajax calls successful");
258                 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
259                 jQuery("#foo").unbind('ajaxError');
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(true); // 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(true); // 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         window.testFoo = undefined;
363         window.foobar = null;
364         var verifyEvaluation = function() {
365                 equals( foobar, "bar", 'Check if script src was evaluated after load' );
366                 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
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         testFoo = undefined;
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                 start();
385         });
386 });
387
388 test("load(String, Object, Function)", function() {
389         expect(2);
390         stop();
391         
392         jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
393                 var $post = jQuery(this).find('#post');         
394                 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
395                 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
396                 start();
397         });
398 });
399
400 test("load(String, String, Function)", function() {
401         expect(2);
402         stop();
403         
404         jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
405                 var $get = jQuery(this).find('#get');           
406                 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
407                 equals( $get.find('#bar').text(), 'ok', 'Check if a  of data is passed correctly');
408                 start();
409         });
410 });
411
412 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
413         expect(2);
414         stop();
415         jQuery.get(url('data/dashboard.xml'), function(xml) {
416                 var content = [];
417                 jQuery('tab', xml).each(function() {
418                         content.push(jQuery(this).text());
419                 });
420                 equals( content[0], 'blabla', 'Check first tab');
421                 equals( content[1], 'blublu', 'Check second tab');
422                 start();
423         });
424 });
425
426 test("jQuery.getScript(String, Function) - with callback", function() {
427         expect(2);
428         stop();
429         window.foobar = null;
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(true);
439         jQuery.getScript(url("data/test.js"), start);
440 });
441
442 test("jQuery.ajax() - JSONP, Local", function() {
443         expect(7);
444
445         var count = 0;
446         function plus(){ if ( ++count == 7 ) start(); }
447
448         stop();
449
450         jQuery.ajax({
451                 url: "data/jsonp.php",
452                 dataType: "jsonp",
453                 success: function(data){
454                         ok( data.data, "JSON results returned (GET, no callback)" );
455                         plus();
456                 },
457                 error: function(data){
458                         ok( false, "Ajax error JSON (GET, no callback)" );
459                         plus();
460                 }
461         });
462
463         jQuery.ajax({
464                 url: "data/jsonp.php?callback=?",
465                 dataType: "jsonp",
466                 success: function(data){
467                         ok( data.data, "JSON results returned (GET, url callback)" );
468                         plus();
469                 },
470                 error: function(data){
471                         ok( false, "Ajax error JSON (GET, url callback)" );
472                         plus();
473                 }
474         });
475
476         jQuery.ajax({
477                 url: "data/jsonp.php",
478                 dataType: "jsonp",
479                 data: "callback=?",
480                 success: function(data){
481                         ok( data.data, "JSON results returned (GET, data callback)" );
482                         plus();
483                 },
484                 error: function(data){
485                         ok( false, "Ajax error JSON (GET, data callback)" );
486                         plus();
487                 }
488         });
489
490         jQuery.ajax({
491                 url: "data/jsonp.php",
492                 dataType: "jsonp",
493                 jsonp: "callback",
494                 success: function(data){
495                         ok( data.data, "JSON results returned (GET, data obj callback)" );
496                         plus();
497                 },
498                 error: function(data){
499                         ok( false, "Ajax error JSON (GET, data obj callback)" );
500                         plus();
501                 }
502         });
503
504         jQuery.ajax({
505                 type: "POST",
506                 url: "data/jsonp.php",
507                 dataType: "jsonp",
508                 success: function(data){
509                         ok( data.data, "JSON results returned (POST, no callback)" );
510                         plus();
511                 },
512                 error: function(data){
513                         ok( false, "Ajax error JSON (GET, data obj callback)" );
514                         plus();
515                 }
516         });
517
518         jQuery.ajax({
519                 type: "POST",
520                 url: "data/jsonp.php",
521                 data: "callback=?",
522                 dataType: "jsonp",
523                 success: function(data){
524                         ok( data.data, "JSON results returned (POST, data callback)" );
525                         plus();
526                 },
527                 error: function(data){
528                         ok( false, "Ajax error JSON (POST, data callback)" );
529                         plus();
530                 }
531         });
532
533         jQuery.ajax({
534                 type: "POST",
535                 url: "data/jsonp.php",
536                 jsonp: "callback",
537                 dataType: "jsonp",
538                 success: function(data){
539                         ok( data.data, "JSON results returned (POST, data obj callback)" );
540                         plus();
541                 },
542                 error: function(data){
543                         ok( false, "Ajax error JSON (POST, data obj callback)" );
544                         plus();
545                 }
546         });
547 });
548
549 test("jQuery.ajax() - JSONP, Remote", function() {
550         expect(4);
551
552         var count = 0;
553         function plus(){ if ( ++count == 4 ) start(); }
554
555         var base = window.location.href.replace(/\?.*$/, "");
556
557         stop();
558
559         jQuery.ajax({
560                 url: base + "data/jsonp.php",
561                 dataType: "jsonp",
562                 success: function(data){
563                         ok( data.data, "JSON results returned (GET, no callback)" );
564                         plus();
565                 },
566                 error: function(data){
567                         ok( false, "Ajax error JSON (GET, no callback)" );
568                         plus();
569                 }
570         });
571
572         jQuery.ajax({
573                 url: base + "data/jsonp.php?callback=?",
574                 dataType: "jsonp",
575                 success: function(data){
576                         ok( data.data, "JSON results returned (GET, url callback)" );
577                         plus();
578                 },
579                 error: function(data){
580                         ok( false, "Ajax error JSON (GET, url callback)" );
581                         plus();
582                 }
583         });
584
585         jQuery.ajax({
586                 url: base + "data/jsonp.php",
587                 dataType: "jsonp",
588                 data: "callback=?",
589                 success: function(data){
590                         ok( data.data, "JSON results returned (GET, data callback)" );
591                         plus();
592                 },
593                 error: function(data){
594                         ok( false, "Ajax error JSON (GET, data callback)" );
595                         plus();
596                 }
597         });
598
599         jQuery.ajax({
600                 url: base + "data/jsonp.php",
601                 dataType: "jsonp",
602                 jsonp: "callback",
603                 success: function(data){
604                         ok( data.data, "JSON results returned (GET, data obj callback)" );
605                         plus();
606                 },
607                 error: function(data){
608                         ok( false, "Ajax error JSON (GET, data obj callback)" );
609                         plus();
610                 }
611         });
612 });
613
614 test("jQuery.ajax() - script, Remote", function() {
615         expect(2);
616
617         var base = window.location.href.replace(/\?.*$/, "");
618
619         stop();
620
621         window.foobar = null;
622         jQuery.ajax({
623                 url: base + "data/test.js",
624                 dataType: "script",
625                 success: function(data){
626                         ok( foobar, "Script results returned (GET, no callback)" );
627                         start();
628                 }
629         });
630 });
631
632 test("jQuery.ajax() - script, Remote with POST", function() {
633         expect(3);
634
635         var base = window.location.href.replace(/\?.*$/, "");
636
637         stop();
638
639         window.foobar = null;
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 (GET, no callback)" );
646                         equals( status, "success", "Script results returned (GET, no callback)" );
647                         start();
648                 }
649         });
650 });
651
652 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
653         expect(2);
654
655         var base = window.location.href.replace(/\?.*$/, "");
656         base = base.replace(/^.*?\/\//, "//");
657
658         stop();
659
660         window.foobar = null;
661         jQuery.ajax({
662                 url: base + "data/test.js",
663                 dataType: "script",
664                 success: function(data){
665                         ok( foobar, "Script results returned (GET, no callback)" );
666                         start();
667                 }
668         });
669 });
670
671 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
672         expect(4);
673         stop();
674         jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
675           equals( json[0].name, 'John', 'Check JSON: first, name' );
676           equals( json[0].age, 21, 'Check JSON: first, age' );
677           equals( json[1].name, 'Peter', 'Check JSON: second, name' );
678           equals( json[1].age, 25, 'Check JSON: second, age' );
679           start();
680         });
681 });
682
683 test("jQuery.getJSON(String, Function) - JSON object", function() {
684         expect(2);
685         stop();
686         jQuery.getJSON(url("data/json.php"), function(json) {
687           equals( json.data.lang, 'en', 'Check JSON: lang' );
688           equals( json.data.length, 25, 'Check JSON: length' );
689           start();
690         });
691 });
692
693 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
694         expect(2);
695
696         var base = window.location.href.replace(/\?.*$/, "");
697
698         stop();
699         jQuery.getJSON(url(base + "data/json.php"), function(json) {
700           equals( json.data.lang, 'en', 'Check JSON: lang' );
701           equals( json.data.length, 25, 'Check JSON: length' );
702           start();
703         });
704 });
705
706 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
707         expect(4);
708         stop();
709         jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
710           jQuery('math', xml).each(function() {
711                     equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
712                     equals( jQuery('result', this).text(), '3', 'Check for XML' );
713                  });
714         });
715
716         jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
717           jQuery('math', xml).each(function() {
718                     equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
719                     equals( jQuery('result', this).text(), '3', 'Check for XML' );
720                  });
721           start();
722         });
723 });
724
725 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
726         stop();
727         
728         var passed = 0;
729
730         jQuery.ajaxSetup({timeout: 1000});
731         
732         var pass = function() {
733                 passed++;
734                 if ( passed == 2 ) {
735                         ok( true, 'Check local and global callbacks after timeout' );
736                 jQuery('#main').unbind("ajaxError");
737                         start();
738                 }
739         };
740         
741         var fail = function(a,b,c) {
742                 ok( false, 'Check for timeout failed ' + a + ' ' + b );
743                 start();
744         };
745         
746         jQuery('#main').ajaxError(pass);
747         
748         jQuery.ajax({
749           type: "GET",
750           url: url("data/name.php?wait=5"),
751           error: pass,
752           success: fail
753         });
754         
755         // reset timeout
756         jQuery.ajaxSetup({timeout: 0});
757 });
758
759 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
760         stop();
761         jQuery.ajaxSetup({timeout: 50});
762
763         jQuery.ajax({
764           type: "GET",
765           timeout: 5000,
766           url: url("data/name.php?wait=1"),
767           error: function() {
768                    ok( false, 'Check for local timeout failed' );
769                    start();
770           },
771           success: function() {
772             ok( true, 'Check for local timeout' );
773             start();
774           }
775         });
776
777         // reset timeout
778         jQuery.ajaxSetup({timeout: 0});
779 });
780
781 test("jQuery.ajax - simple get", function() {
782         expect(1);
783         stop();
784         jQuery.ajax({
785           type: "GET",
786           url: url("data/name.php?name=foo"),
787           success: function(msg){
788             equals( msg, 'bar', 'Check for GET' );
789             start();
790           }
791         });
792 });
793
794 test("jQuery.ajax - simple post", function() {
795         expect(1);
796         stop();
797         jQuery.ajax({
798           type: "POST",
799           url: url("data/name.php"),
800           data: "name=peter",
801           success: function(msg){
802             equals( msg, 'pan', 'Check for POST' );
803             start();
804           }
805         });
806 });
807
808 test("ajaxSetup()", function() {
809         expect(1);
810         stop();
811         jQuery.ajaxSetup({
812                 url: url("data/name.php?name=foo"),
813                 success: function(msg){
814                 equals( msg, 'bar', 'Check for GET' );
815                         start();
816                 }
817         });
818         jQuery.ajax();
819 });
820
821 test("custom timeout does not set error message when timeout occurs, see #970", function() {
822         stop();
823         jQuery.ajax({
824                 url: "data/name.php?wait=10",
825                 timeout: 500,
826                 error: function(request, status) {
827                         ok( status != null, "status shouldn't be null in error handler" );
828                         equals( "timeout", status );
829                         start();
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 //}