test runner: translated all the ok() with '==' to equals(), as it gives more informat...
[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(3);
302
303         var tmp = jQuery.extend({}, jQuery.ajaxSettings);
304     var orig = { url: "data/with_fries.xml", data: null };
305         var t;
306
307         $.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
308
309     t = jQuery.extend({}, orig);
310     $.ajax(t);
311         ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending null" );
312
313     t = jQuery.extend({}, orig);
314         t.data = {};
315     $.ajax(t);
316         ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
317
318     t = jQuery.extend({}, orig);
319         t.data = { zoo: 'a', ping: 'b' };
320     $.ajax(t);
321         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' }" );
322         
323         jQuery.ajaxSettings = tmp;
324 });
325
326 test("load(String)", function() {
327         expect(1);
328         stop(true); // check if load can be called with only url
329         $('#first').load("data/name.html", start);
330 });
331
332 test("load('url selector')", function() {
333         expect(1);
334         stop(true); // check if load can be called with only url
335         $('#first').load("data/test3.html div.user", function(){
336                 equals( $(this).children("div").length, 2, "Verify that specific elements were injected" );
337                 start();
338         });
339 });
340
341 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
342         expect(1);
343         stop();
344         $.ajaxSetup({ dataType: "json" });
345         $("#first").ajaxComplete(function (e, xml, s) {
346                 equals( s.dataType, "html", "Verify the load() dataType was html" );
347                 $("#first").unbind("ajaxComplete");
348                 $.ajaxSetup({ dataType: "" });
349                 start();
350         });
351         $('#first').load("data/test3.html");
352 });
353
354 test("load(String, Function) - simple: inject text into DOM", function() {
355         expect(2);
356         stop();
357         $('#first').load(url("data/name.html"), function() {
358                 ok( /^ERROR/.test($('#first').text()), 'Check if content was injected into the DOM' );
359                 start();
360         });
361 });
362
363 test("load(String, Function) - check scripts", function() {
364         expect(7);
365         stop();
366         window.testFoo = undefined;
367         window.foobar = null;
368         var verifyEvaluation = function() {
369                 equals( foobar, "bar", 'Check if script src was evaluated after load' );
370                 equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
371                  start();
372         };
373         $('#first').load(url('data/test.html'), function() {
374                 ok( $('#first').html().match(/^html text/), 'Check content after loading html' );
375                 equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
376                 equals( testFoo, "foo", 'Check if script was evaluated after load' );
377                 setTimeout(verifyEvaluation, 600);
378         });
379 });
380
381 test("load(String, Function) - check file with only a script tag", function() {
382         expect(3);
383         stop();
384         testFoo = undefined;
385         $('#first').load(url('data/test2.html'), function() {
386                 equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
387                 equals( testFoo, "foo", 'Check if script was evaluated after load' );
388                 start();
389         });
390 });
391
392 test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
393         expect(2);
394         stop();
395         $.get(url('data/dashboard.xml'), function(xml) {
396                 var content = [];
397                 $('tab', xml).each(function() {
398                         content.push($(this).text());
399                 });
400                 equals( content[0], 'blabla', 'Check first tab');
401                 equals( content[1], 'blublu', 'Check second tab');
402                 start();
403         });
404 });
405
406 test("$.getScript(String, Function) - with callback", function() {
407         expect(2);
408         stop();
409         window.foobar = null;
410         $.getScript(url("data/test.js"), function() {
411                 equals( foobar, "bar", 'Check if script was evaluated' );
412                 setTimeout(start, 100);
413         });
414 });
415
416 test("$.getScript(String, Function) - no callback", function() {
417         expect(1);
418         stop(true);
419         $.getScript(url("data/test.js"), start);
420 });
421
422 test("$.ajax() - JSONP, Local", function() {
423         expect(7);
424
425         var count = 0;
426         function plus(){ if ( ++count == 7 ) start(); }
427
428         stop();
429
430         $.ajax({
431                 url: "data/jsonp.php",
432                 dataType: "jsonp",
433                 success: function(data){
434                         ok( data.data, "JSON results returned (GET, no callback)" );
435                         plus();
436                 },
437                 error: function(data){
438                         ok( false, "Ajax error JSON (GET, no callback)" );
439                         plus();
440                 }
441         });
442
443         $.ajax({
444                 url: "data/jsonp.php?callback=?",
445                 dataType: "jsonp",
446                 success: function(data){
447                         ok( data.data, "JSON results returned (GET, url callback)" );
448                         plus();
449                 },
450                 error: function(data){
451                         ok( false, "Ajax error JSON (GET, url callback)" );
452                         plus();
453                 }
454         });
455
456         $.ajax({
457                 url: "data/jsonp.php",
458                 dataType: "jsonp",
459                 data: "callback=?",
460                 success: function(data){
461                         ok( data.data, "JSON results returned (GET, data callback)" );
462                         plus();
463                 },
464                 error: function(data){
465                         ok( false, "Ajax error JSON (GET, data callback)" );
466                         plus();
467                 }
468         });
469
470         $.ajax({
471                 url: "data/jsonp.php",
472                 dataType: "jsonp",
473                 jsonp: "callback",
474                 success: function(data){
475                         ok( data.data, "JSON results returned (GET, data obj callback)" );
476                         plus();
477                 },
478                 error: function(data){
479                         ok( false, "Ajax error JSON (GET, data obj callback)" );
480                         plus();
481                 }
482         });
483
484         $.ajax({
485                 type: "POST",
486                 url: "data/jsonp.php",
487                 dataType: "jsonp",
488                 success: function(data){
489                         ok( data.data, "JSON results returned (POST, no callback)" );
490                         plus();
491                 },
492                 error: function(data){
493                         ok( false, "Ajax error JSON (GET, data obj callback)" );
494                         plus();
495                 }
496         });
497
498         $.ajax({
499                 type: "POST",
500                 url: "data/jsonp.php",
501                 data: "callback=?",
502                 dataType: "jsonp",
503                 success: function(data){
504                         ok( data.data, "JSON results returned (POST, data callback)" );
505                         plus();
506                 },
507                 error: function(data){
508                         ok( false, "Ajax error JSON (POST, data callback)" );
509                         plus();
510                 }
511         });
512
513         $.ajax({
514                 type: "POST",
515                 url: "data/jsonp.php",
516                 jsonp: "callback",
517                 dataType: "jsonp",
518                 success: function(data){
519                         ok( data.data, "JSON results returned (POST, data obj callback)" );
520                         plus();
521                 },
522                 error: function(data){
523                         ok( false, "Ajax error JSON (POST, data obj callback)" );
524                         plus();
525                 }
526         });
527 });
528
529 test("$.ajax() - JSONP, Remote", function() {
530         expect(4);
531
532         var count = 0;
533         function plus(){ if ( ++count == 4 ) start(); }
534
535         var base = window.location.href.replace(/\?.*$/, "");
536
537         stop();
538
539         $.ajax({
540                 url: base + "data/jsonp.php",
541                 dataType: "jsonp",
542                 success: function(data){
543                         ok( data.data, "JSON results returned (GET, no callback)" );
544                         plus();
545                 },
546                 error: function(data){
547                         ok( false, "Ajax error JSON (GET, no callback)" );
548                         plus();
549                 }
550         });
551
552         $.ajax({
553                 url: base + "data/jsonp.php?callback=?",
554                 dataType: "jsonp",
555                 success: function(data){
556                         ok( data.data, "JSON results returned (GET, url callback)" );
557                         plus();
558                 },
559                 error: function(data){
560                         ok( false, "Ajax error JSON (GET, url callback)" );
561                         plus();
562                 }
563         });
564
565         $.ajax({
566                 url: base + "data/jsonp.php",
567                 dataType: "jsonp",
568                 data: "callback=?",
569                 success: function(data){
570                         ok( data.data, "JSON results returned (GET, data callback)" );
571                         plus();
572                 },
573                 error: function(data){
574                         ok( false, "Ajax error JSON (GET, data callback)" );
575                         plus();
576                 }
577         });
578
579         $.ajax({
580                 url: base + "data/jsonp.php",
581                 dataType: "jsonp",
582                 jsonp: "callback",
583                 success: function(data){
584                         ok( data.data, "JSON results returned (GET, data obj callback)" );
585                         plus();
586                 },
587                 error: function(data){
588                         ok( false, "Ajax error JSON (GET, data obj callback)" );
589                         plus();
590                 }
591         });
592 });
593
594 test("$.ajax() - script, Remote", function() {
595         expect(2);
596
597         var base = window.location.href.replace(/\?.*$/, "");
598
599         stop();
600
601         window.foobar = null;
602         $.ajax({
603                 url: base + "data/test.js",
604                 dataType: "script",
605                 success: function(data){
606                         ok( foobar, "Script results returned (GET, no callback)" );
607                         start();
608                 }
609         });
610 });
611
612 test("$.ajax() - script, Remote with POST", function() {
613         expect(3);
614
615         var base = window.location.href.replace(/\?.*$/, "");
616
617         stop();
618
619         window.foobar = null;
620         $.ajax({
621                 url: base + "data/test.js",
622                 type: "POST",
623                 dataType: "script",
624                 success: function(data, status){
625                         ok( foobar, "Script results returned (GET, no callback)" );
626                         equals( status, "success", "Script results returned (GET, no callback)" );
627                         start();
628                 }
629         });
630 });
631
632 test("$.ajax() - script, Remote with scheme-less URL", function() {
633         expect(2);
634
635         var base = window.location.href.replace(/\?.*$/, "");
636         base = base.replace(/^.*?\/\//, "//");
637
638         stop();
639
640         window.foobar = null;
641         $.ajax({
642                 url: base + "data/test.js",
643                 dataType: "script",
644                 success: function(data){
645                         ok( foobar, "Script results returned (GET, no callback)" );
646                         start();
647                 }
648         });
649 });
650
651 test("$.getJSON(String, Hash, Function) - JSON array", function() {
652         expect(4);
653         stop();
654         $.getJSON(url("data/json.php"), {json: "array"}, function(json) {
655           equals( json[0].name, 'John', 'Check JSON: first, name' );
656           equals( json[0].age, 21, 'Check JSON: first, age' );
657           equals( json[1].name, 'Peter', 'Check JSON: second, name' );
658           equals( json[1].age, 25, 'Check JSON: second, age' );
659           start();
660         });
661 });
662
663 test("$.getJSON(String, Function) - JSON object", function() {
664         expect(2);
665         stop();
666         $.getJSON(url("data/json.php"), function(json) {
667           equals( json.data.lang, 'en', 'Check JSON: lang' );
668           equals( json.data.length, 25, 'Check JSON: length' );
669           start();
670         });
671 });
672
673 test("$.getJSON(String, Function) - JSON object with absolute url to local content", function() {
674         expect(2);
675
676         var base = window.location.href.replace(/\?.*$/, "");
677
678         stop();
679         $.getJSON(url(base + "data/json.php"), function(json) {
680           equals( json.data.lang, 'en', 'Check JSON: lang' );
681           equals( json.data.length, 25, 'Check JSON: length' );
682           start();
683         });
684 });
685
686 test("$.post(String, Hash, Function) - simple with xml", function() {
687         expect(4);
688         stop();
689         $.post(url("data/name.php"), {xml: "5-2"}, function(xml){
690           $('math', xml).each(function() {
691                     equals( $('calculation', this).text(), '5-2', 'Check for XML' );
692                     equals( $('result', this).text(), '3', 'Check for XML' );
693                  });
694         });
695
696         $.post(url("data/name.php?xml=5-2"), {}, function(xml){
697           $('math', xml).each(function() {
698                     equals( $('calculation', this).text(), '5-2', 'Check for XML' );
699                     equals( $('result', this).text(), '3', 'Check for XML' );
700                  });
701           start();
702         });
703 });
704
705 test("$.ajaxSetup({timeout: Number}) - with global timeout", function() {
706         stop();
707         
708         var passed = 0;
709
710         $.ajaxSetup({timeout: 1000});
711         
712         var pass = function() {
713                 passed++;
714                 if ( passed == 2 ) {
715                         ok( true, 'Check local and global callbacks after timeout' );
716                 $('#main').unbind("ajaxError");
717                         start();
718                 }
719         };
720         
721         var fail = function(a,b,c) {
722                 ok( false, 'Check for timeout failed ' + a + ' ' + b );
723                 start();
724         };
725         
726         $('#main').ajaxError(pass);
727         
728         $.ajax({
729           type: "GET",
730           url: url("data/name.php?wait=5"),
731           error: pass,
732           success: fail
733         });
734         
735         // reset timeout
736         $.ajaxSetup({timeout: 0});
737 });
738
739 test("$.ajaxSetup({timeout: Number}) with localtimeout", function() {
740         stop();
741         $.ajaxSetup({timeout: 50});
742
743         $.ajax({
744           type: "GET",
745           timeout: 5000,
746           url: url("data/name.php?wait=1"),
747           error: function() {
748                    ok( false, 'Check for local timeout failed' );
749                    start();
750           },
751           success: function() {
752             ok( true, 'Check for local timeout' );
753             start();
754           }
755         });
756
757         // reset timeout
758         $.ajaxSetup({timeout: 0});
759 });
760
761 test("$.ajax - simple get", function() {
762         expect(1);
763         stop();
764         $.ajax({
765           type: "GET",
766           url: url("data/name.php?name=foo"),
767           success: function(msg){
768             equals( msg, 'bar', 'Check for GET' );
769             start();
770           }
771         });
772 });
773
774 test("$.ajax - simple post", function() {
775         expect(1);
776         stop();
777         $.ajax({
778           type: "POST",
779           url: url("data/name.php"),
780           data: "name=peter",
781           success: function(msg){
782             equals( msg, 'pan', 'Check for POST' );
783             start();
784           }
785         });
786 });
787
788 test("ajaxSetup()", function() {
789         expect(1);
790         stop();
791         $.ajaxSetup({
792                 url: url("data/name.php?name=foo"),
793                 success: function(msg){
794                 equals( msg, 'bar', 'Check for GET' );
795                         start();
796                 }
797         });
798         $.ajax();
799 });
800
801 test("custom timeout does not set error message when timeout occurs, see #970", function() {
802         stop();
803         $.ajax({
804                 url: "data/name.php?wait=10",
805                 timeout: 500,
806                 error: function(request, status) {
807                         ok( status != null, "status shouldn't be null in error handler" );
808                         equals( "timeout", status );
809                         start();
810                 }
811         });
812 });
813
814 }
815
816 //}