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