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