ajax test: Removed test for extending with null.
[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("$.ajax() - success callbacks", function() {
11         expect( 8 );
12         
13         $.ajaxSetup({ timeout: 0 });
14         
15         stop();
16         
17         setTimeout(function(){  
18         $('#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         $.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("$.ajax() - error callbacks", function() {
44     expect( 8 );
45     stop();
46     
47     $('#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     $.ajaxSetup({ timeout: 500 });
63     
64     $.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("$.ajax() - disabled globals", function() {
74         expect( 3 );
75         stop();
76         
77         $('#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         $.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("$.ajax - xml: non-namespace elements inside namespaced elements", function() {
105         expect(3);
106         stop();
107         $.ajax({
108           url: url("data/with_fries.xml"),
109           dataType: "xml",
110           success: function(resp) {
111             equals( $("properties", resp).length, 1, 'properties in responseXML' );
112             equals( $("jsconf", resp).length, 1, 'jsconf in responseXML' );
113             equals( $("thing", resp).length, 2, 'things in responseXML' );
114             start();
115           }
116         });
117 });
118
119 test("$.ajax - beforeSend", function() {
120         expect(1);
121         stop();
122         
123         var check = false;
124         
125         $.ajaxSetup({ timeout: 0 });
126         
127         $.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("$.ajax - beforeSend, cancel request (#2688)", function() {
140         expect(2);
141         var request = $.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("$.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         $.ajax({
176           dataType: "html",
177           url: url("data/test.html"),
178           success: function(data) {
179                 $("#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( $('#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( $('#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( $('#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( $('#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( $('#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( $('#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("$.param()", function() {
215         expect(4);
216         var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
217         equals( $.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( $.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( $.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( $.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( $.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         $.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         $("#foo").ajaxError(function (e, xml, s, ex) {
253                 errorCount++;
254     errorEx += ": " + xml.status;
255         });
256         $("#foo").one('ajaxStop', function () {
257                 equals(successCount, 5, "Check all ajax calls successful");
258                 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
259                 $("#foo").unbind('ajaxError');
260                 start();
261         });
262         
263         ok( $.get(url(target), success), "get" );
264         ok( $.post(url(target), success), "post" );
265         ok( $.getScript(url("data/test.js"), success), "script" );
266         ok( $.getJSON(url("data/json_obj.js"), success), "json" );
267         ok( $.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         $("#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( $.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
293         ok( $.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
294         ok( $.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
295         ok( $.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
296         ok( $.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
297         ok( $.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         $.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
308
309     t = jQuery.extend({}, orig);
310         t.data = {};
311     $.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     $.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         $('#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         $('#first').load("data/test3.html div.user", function(){
332                 equals( $(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         $.ajaxSetup({ dataType: "json" });
341         $("#first").ajaxComplete(function (e, xml, s) {
342                 equals( s.dataType, "html", "Verify the load() dataType was html" );
343                 $("#first").unbind("ajaxComplete");
344                 $.ajaxSetup({ dataType: "" });
345                 start();
346         });
347         $('#first').load("data/test3.html");
348 });
349
350 test("load(String, Function) - simple: inject text into DOM", function() {
351         expect(2);
352         stop();
353         $('#first').load(url("data/name.html"), function() {
354                 ok( /^ERROR/.test($('#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( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
367                  start();
368         };
369         $('#first').load(url('data/test.html'), function() {
370                 ok( $('#first').html().match(/^html text/), 'Check content after loading html' );
371                 equals( $('#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         $('#first').load(url('data/test2.html'), function() {
382                 equals( $('#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("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
389         expect(2);
390         stop();
391         $.get(url('data/dashboard.xml'), function(xml) {
392                 var content = [];
393                 $('tab', xml).each(function() {
394                         content.push($(this).text());
395                 });
396                 equals( content[0], 'blabla', 'Check first tab');
397                 equals( content[1], 'blublu', 'Check second tab');
398                 start();
399         });
400 });
401
402 test("$.getScript(String, Function) - with callback", function() {
403         expect(2);
404         stop();
405         window.foobar = null;
406         $.getScript(url("data/test.js"), function() {
407                 equals( foobar, "bar", 'Check if script was evaluated' );
408                 setTimeout(start, 100);
409         });
410 });
411
412 test("$.getScript(String, Function) - no callback", function() {
413         expect(1);
414         stop(true);
415         $.getScript(url("data/test.js"), start);
416 });
417
418 test("$.ajax() - JSONP, Local", function() {
419         expect(7);
420
421         var count = 0;
422         function plus(){ if ( ++count == 7 ) start(); }
423
424         stop();
425
426         $.ajax({
427                 url: "data/jsonp.php",
428                 dataType: "jsonp",
429                 success: function(data){
430                         ok( data.data, "JSON results returned (GET, no callback)" );
431                         plus();
432                 },
433                 error: function(data){
434                         ok( false, "Ajax error JSON (GET, no callback)" );
435                         plus();
436                 }
437         });
438
439         $.ajax({
440                 url: "data/jsonp.php?callback=?",
441                 dataType: "jsonp",
442                 success: function(data){
443                         ok( data.data, "JSON results returned (GET, url callback)" );
444                         plus();
445                 },
446                 error: function(data){
447                         ok( false, "Ajax error JSON (GET, url callback)" );
448                         plus();
449                 }
450         });
451
452         $.ajax({
453                 url: "data/jsonp.php",
454                 dataType: "jsonp",
455                 data: "callback=?",
456                 success: function(data){
457                         ok( data.data, "JSON results returned (GET, data callback)" );
458                         plus();
459                 },
460                 error: function(data){
461                         ok( false, "Ajax error JSON (GET, data callback)" );
462                         plus();
463                 }
464         });
465
466         $.ajax({
467                 url: "data/jsonp.php",
468                 dataType: "jsonp",
469                 jsonp: "callback",
470                 success: function(data){
471                         ok( data.data, "JSON results returned (GET, data obj callback)" );
472                         plus();
473                 },
474                 error: function(data){
475                         ok( false, "Ajax error JSON (GET, data obj callback)" );
476                         plus();
477                 }
478         });
479
480         $.ajax({
481                 type: "POST",
482                 url: "data/jsonp.php",
483                 dataType: "jsonp",
484                 success: function(data){
485                         ok( data.data, "JSON results returned (POST, no callback)" );
486                         plus();
487                 },
488                 error: function(data){
489                         ok( false, "Ajax error JSON (GET, data obj callback)" );
490                         plus();
491                 }
492         });
493
494         $.ajax({
495                 type: "POST",
496                 url: "data/jsonp.php",
497                 data: "callback=?",
498                 dataType: "jsonp",
499                 success: function(data){
500                         ok( data.data, "JSON results returned (POST, data callback)" );
501                         plus();
502                 },
503                 error: function(data){
504                         ok( false, "Ajax error JSON (POST, data callback)" );
505                         plus();
506                 }
507         });
508
509         $.ajax({
510                 type: "POST",
511                 url: "data/jsonp.php",
512                 jsonp: "callback",
513                 dataType: "jsonp",
514                 success: function(data){
515                         ok( data.data, "JSON results returned (POST, data obj callback)" );
516                         plus();
517                 },
518                 error: function(data){
519                         ok( false, "Ajax error JSON (POST, data obj callback)" );
520                         plus();
521                 }
522         });
523 });
524
525 test("$.ajax() - JSONP, Remote", function() {
526         expect(4);
527
528         var count = 0;
529         function plus(){ if ( ++count == 4 ) start(); }
530
531         var base = window.location.href.replace(/\?.*$/, "");
532
533         stop();
534
535         $.ajax({
536                 url: base + "data/jsonp.php",
537                 dataType: "jsonp",
538                 success: function(data){
539                         ok( data.data, "JSON results returned (GET, no callback)" );
540                         plus();
541                 },
542                 error: function(data){
543                         ok( false, "Ajax error JSON (GET, no callback)" );
544                         plus();
545                 }
546         });
547
548         $.ajax({
549                 url: base + "data/jsonp.php?callback=?",
550                 dataType: "jsonp",
551                 success: function(data){
552                         ok( data.data, "JSON results returned (GET, url callback)" );
553                         plus();
554                 },
555                 error: function(data){
556                         ok( false, "Ajax error JSON (GET, url callback)" );
557                         plus();
558                 }
559         });
560
561         $.ajax({
562                 url: base + "data/jsonp.php",
563                 dataType: "jsonp",
564                 data: "callback=?",
565                 success: function(data){
566                         ok( data.data, "JSON results returned (GET, data callback)" );
567                         plus();
568                 },
569                 error: function(data){
570                         ok( false, "Ajax error JSON (GET, data callback)" );
571                         plus();
572                 }
573         });
574
575         $.ajax({
576                 url: base + "data/jsonp.php",
577                 dataType: "jsonp",
578                 jsonp: "callback",
579                 success: function(data){
580                         ok( data.data, "JSON results returned (GET, data obj callback)" );
581                         plus();
582                 },
583                 error: function(data){
584                         ok( false, "Ajax error JSON (GET, data obj callback)" );
585                         plus();
586                 }
587         });
588 });
589
590 test("$.ajax() - script, Remote", function() {
591         expect(2);
592
593         var base = window.location.href.replace(/\?.*$/, "");
594
595         stop();
596
597         window.foobar = null;
598         $.ajax({
599                 url: base + "data/test.js",
600                 dataType: "script",
601                 success: function(data){
602                         ok( foobar, "Script results returned (GET, no callback)" );
603                         start();
604                 }
605         });
606 });
607
608 test("$.ajax() - script, Remote with POST", function() {
609         expect(3);
610
611         var base = window.location.href.replace(/\?.*$/, "");
612
613         stop();
614
615         window.foobar = null;
616         $.ajax({
617                 url: base + "data/test.js",
618                 type: "POST",
619                 dataType: "script",
620                 success: function(data, status){
621                         ok( foobar, "Script results returned (GET, no callback)" );
622                         equals( status, "success", "Script results returned (GET, no callback)" );
623                         start();
624                 }
625         });
626 });
627
628 test("$.ajax() - script, Remote with scheme-less URL", function() {
629         expect(2);
630
631         var base = window.location.href.replace(/\?.*$/, "");
632         base = base.replace(/^.*?\/\//, "//");
633
634         stop();
635
636         window.foobar = null;
637         $.ajax({
638                 url: base + "data/test.js",
639                 dataType: "script",
640                 success: function(data){
641                         ok( foobar, "Script results returned (GET, no callback)" );
642                         start();
643                 }
644         });
645 });
646
647 test("$.getJSON(String, Hash, Function) - JSON array", function() {
648         expect(4);
649         stop();
650         $.getJSON(url("data/json.php"), {json: "array"}, function(json) {
651           equals( json[0].name, 'John', 'Check JSON: first, name' );
652           equals( json[0].age, 21, 'Check JSON: first, age' );
653           equals( json[1].name, 'Peter', 'Check JSON: second, name' );
654           equals( json[1].age, 25, 'Check JSON: second, age' );
655           start();
656         });
657 });
658
659 test("$.getJSON(String, Function) - JSON object", function() {
660         expect(2);
661         stop();
662         $.getJSON(url("data/json.php"), function(json) {
663           equals( json.data.lang, 'en', 'Check JSON: lang' );
664           equals( json.data.length, 25, 'Check JSON: length' );
665           start();
666         });
667 });
668
669 test("$.getJSON(String, Function) - JSON object with absolute url to local content", function() {
670         expect(2);
671
672         var base = window.location.href.replace(/\?.*$/, "");
673
674         stop();
675         $.getJSON(url(base + "data/json.php"), function(json) {
676           equals( json.data.lang, 'en', 'Check JSON: lang' );
677           equals( json.data.length, 25, 'Check JSON: length' );
678           start();
679         });
680 });
681
682 test("$.post(String, Hash, Function) - simple with xml", function() {
683         expect(4);
684         stop();
685         $.post(url("data/name.php"), {xml: "5-2"}, function(xml){
686           $('math', xml).each(function() {
687                     equals( $('calculation', this).text(), '5-2', 'Check for XML' );
688                     equals( $('result', this).text(), '3', 'Check for XML' );
689                  });
690         });
691
692         $.post(url("data/name.php?xml=5-2"), {}, function(xml){
693           $('math', xml).each(function() {
694                     equals( $('calculation', this).text(), '5-2', 'Check for XML' );
695                     equals( $('result', this).text(), '3', 'Check for XML' );
696                  });
697           start();
698         });
699 });
700
701 test("$.ajaxSetup({timeout: Number}) - with global timeout", function() {
702         stop();
703         
704         var passed = 0;
705
706         $.ajaxSetup({timeout: 1000});
707         
708         var pass = function() {
709                 passed++;
710                 if ( passed == 2 ) {
711                         ok( true, 'Check local and global callbacks after timeout' );
712                 $('#main').unbind("ajaxError");
713                         start();
714                 }
715         };
716         
717         var fail = function(a,b,c) {
718                 ok( false, 'Check for timeout failed ' + a + ' ' + b );
719                 start();
720         };
721         
722         $('#main').ajaxError(pass);
723         
724         $.ajax({
725           type: "GET",
726           url: url("data/name.php?wait=5"),
727           error: pass,
728           success: fail
729         });
730         
731         // reset timeout
732         $.ajaxSetup({timeout: 0});
733 });
734
735 test("$.ajaxSetup({timeout: Number}) with localtimeout", function() {
736         stop();
737         $.ajaxSetup({timeout: 50});
738
739         $.ajax({
740           type: "GET",
741           timeout: 5000,
742           url: url("data/name.php?wait=1"),
743           error: function() {
744                    ok( false, 'Check for local timeout failed' );
745                    start();
746           },
747           success: function() {
748             ok( true, 'Check for local timeout' );
749             start();
750           }
751         });
752
753         // reset timeout
754         $.ajaxSetup({timeout: 0});
755 });
756
757 test("$.ajax - simple get", function() {
758         expect(1);
759         stop();
760         $.ajax({
761           type: "GET",
762           url: url("data/name.php?name=foo"),
763           success: function(msg){
764             equals( msg, 'bar', 'Check for GET' );
765             start();
766           }
767         });
768 });
769
770 test("$.ajax - simple post", function() {
771         expect(1);
772         stop();
773         $.ajax({
774           type: "POST",
775           url: url("data/name.php"),
776           data: "name=peter",
777           success: function(msg){
778             equals( msg, 'pan', 'Check for POST' );
779             start();
780           }
781         });
782 });
783
784 test("ajaxSetup()", function() {
785         expect(1);
786         stop();
787         $.ajaxSetup({
788                 url: url("data/name.php?name=foo"),
789                 success: function(msg){
790                 equals( msg, 'bar', 'Check for GET' );
791                         start();
792                 }
793         });
794         $.ajax();
795 });
796
797 test("custom timeout does not set error message when timeout occurs, see #970", function() {
798         stop();
799         $.ajax({
800                 url: "data/name.php?wait=10",
801                 timeout: 500,
802                 error: function(request, status) {
803                         ok( status != null, "status shouldn't be null in error handler" );
804                         equals( "timeout", status );
805                         start();
806                 }
807         });
808 });
809
810 test("data option: evaluate function values (#2806)", function() {
811         stop();
812         $.ajax({
813                 url: "data/echoQuery.php",
814                 data: {
815                         key: function() {
816                                 return "value";
817                         }
818                 },
819                 success: function(result) {
820                         equals( result, "key=value" );
821                         start();
822                 }
823         })
824 });
825
826 }
827
828 //}