1 module("ajax", { teardown: moduleTeardown });
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 ) {
10 test("jQuery.ajax() - success callbacks", function() {
13 jQuery.ajaxSetup({ timeout: 0 });
17 jQuery('#foo').ajaxStart(function(){
18 ok( true, "ajaxStart" );
19 }).ajaxStop(function(){
20 ok( true, "ajaxStop" );
22 }).ajaxSend(function(){
23 ok( true, "ajaxSend" );
24 }).ajaxComplete(function(){
25 ok( true, "ajaxComplete" );
26 }).ajaxError(function(){
27 ok( false, "ajaxError" );
28 }).ajaxSuccess(function(){
29 ok( true, "ajaxSuccess" );
33 url: url("data/name.html"),
34 beforeSend: function(){ ok(true, "beforeSend"); },
35 success: function(){ ok(true, "success"); },
36 error: function(){ ok(false, "error"); },
37 complete: function(){ ok(true, "complete"); }
41 test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
44 jQuery.ajaxSetup({ timeout: 0 });
48 setTimeout(function(){
49 jQuery('#foo').ajaxStart(function(){
50 ok( true, "ajaxStart" );
51 }).ajaxStop(function(){
52 ok( true, "ajaxStop" );
54 }).ajaxSend(function(){
55 ok( true, "ajaxSend" );
56 }).ajaxComplete(function(){
57 ok( true, "ajaxComplete" );
58 }).ajaxError(function(){
59 ok( false, "ajaxError" );
60 }).ajaxSuccess(function(){
61 ok( true, "ajaxSuccess" );
64 jQuery.ajax( url("data/name.html") , {
65 beforeSend: function(){ ok(true, "beforeSend"); },
66 success: function(){ ok(true, "success"); },
67 error: function(){ ok(false, "error"); },
68 complete: function(){ ok(true, "complete"); }
73 test("jQuery.ajax() - success callbacks (late binding)", function() {
76 jQuery.ajaxSetup({ timeout: 0 });
80 setTimeout(function(){
81 jQuery('#foo').ajaxStart(function(){
82 ok( true, "ajaxStart" );
83 }).ajaxStop(function(){
84 ok( true, "ajaxStop" );
86 }).ajaxSend(function(){
87 ok( true, "ajaxSend" );
88 }).ajaxComplete(function(){
89 ok( true, "ajaxComplete" );
90 }).ajaxError(function(){
91 ok( false, "ajaxError" );
92 }).ajaxSuccess(function(){
93 ok( true, "ajaxSuccess" );
97 url: url("data/name.html"),
98 beforeSend: function(){ ok(true, "beforeSend"); }
100 .complete(function(){ ok(true, "complete"); })
101 .success(function(){ ok(true, "success"); })
102 .error(function(){ ok(false, "error"); });
106 test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
109 jQuery.ajaxSetup({ timeout: 0 });
113 setTimeout(function(){
114 jQuery('#foo').ajaxStart(function(){
115 ok( true, "ajaxStart" );
116 }).ajaxStop(function(){
117 ok( true, "ajaxStop" );
118 }).ajaxSend(function(){
119 ok( true, "ajaxSend" );
120 }).ajaxComplete(function(){
121 ok( true, "ajaxComplete" );
122 }).ajaxError(function(){
123 ok( false, "ajaxError" );
124 }).ajaxSuccess(function(){
125 ok( true, "ajaxSuccess" );
129 url: url("data/name.html"),
130 beforeSend: function(){ ok(true, "beforeSend"); },
131 complete: function(xhr) {
133 .complete(function(){ ok(true, "complete"); })
134 .success(function(){ ok(true, "success"); })
135 .error(function(){ ok(false, "error"); })
136 .complete(function(){ start(); });
142 test("jQuery.ajax() - success callbacks (very late binding)", function() {
145 jQuery.ajaxSetup({ timeout: 0 });
149 setTimeout(function(){
150 jQuery('#foo').ajaxStart(function(){
151 ok( true, "ajaxStart" );
152 }).ajaxStop(function(){
153 ok( true, "ajaxStop" );
154 }).ajaxSend(function(){
155 ok( true, "ajaxSend" );
156 }).ajaxComplete(function(){
157 ok( true, "ajaxComplete" );
158 }).ajaxError(function(){
159 ok( false, "ajaxError" );
160 }).ajaxSuccess(function(){
161 ok( true, "ajaxSuccess" );
165 url: url("data/name.html"),
166 beforeSend: function(){ ok(true, "beforeSend"); },
167 complete: function(xhr) {
168 setTimeout (function() {
170 .complete(function(){ ok(true, "complete"); })
171 .success(function(){ ok(true, "success"); })
172 .error(function(){ ok(false, "error"); })
173 .complete(function(){ start(); });
180 test("jQuery.ajax() - success callbacks (order)", function() {
183 jQuery.ajaxSetup({ timeout: 0 });
189 setTimeout(function(){
191 url: url("data/name.html"),
192 success: function( _1 , _2 , xhr ) {
193 xhr.success(function() {
194 xhr.success(function() {
201 complete: function() {
202 strictEqual(testString, "ABCDE", "Proper order");
205 }).success(function() {
207 }).success(function() {
213 test("jQuery.ajax() - error callbacks", function() {
217 jQuery('#foo').ajaxStart(function(){
218 ok( true, "ajaxStart" );
219 }).ajaxStop(function(){
220 ok( true, "ajaxStop" );
222 }).ajaxSend(function(){
223 ok( true, "ajaxSend" );
224 }).ajaxComplete(function(){
225 ok( true, "ajaxComplete" );
226 }).ajaxError(function(){
227 ok( true, "ajaxError" );
228 }).ajaxSuccess(function(){
229 ok( false, "ajaxSuccess" );
232 jQuery.ajaxSetup({ timeout: 500 });
235 url: url("data/name.php?wait=5"),
236 beforeSend: function(){ ok(true, "beforeSend"); },
237 success: function(){ ok(false, "success"); },
238 error: function(){ ok(true, "error"); },
239 complete: function(){ ok(true, "complete"); }
243 test("jQuery.ajax() - responseText on error", function() {
250 url: url("data/errorWithText.php"),
251 error: function(xhr) {
252 strictEqual( xhr.responseText , "plain text message" , "Test jXHR.responseText is filled for HTTP errors" );
254 complete: function() {
260 test(".ajax() - retry with jQuery.ajax( this )", function() {
269 url: url("data/errorWithText.php"),
275 ok( true , "Test retrying with jQuery.ajax(this) works" );
283 test(".ajax() - headers" , function() {
289 var requestHeaders = {
291 "SometHing-elsE": "other value",
292 OthEr: "something else"
297 for( i in requestHeaders ) {
301 jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
302 headers: requestHeaders,
303 success: function( data , _ , xhr ) {
305 for ( i in requestHeaders ) {
306 tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
308 tmp = tmp.join( "" );
310 equals( data , tmp , "Headers were sent" );
311 equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
314 error: function(){ ok(false, "error"); }
319 test(".ajax() - Accept header" , function() {
325 jQuery.ajax(url("data/headers.php?keys=accept"), {
327 Accept: "very wrong accept value"
329 beforeSend: function( xhr ) {
330 xhr.setRequestHeader( "Accept", "*/*" );
332 success: function( data ) {
333 strictEqual( data , "accept: */*\n" , "Test Accept header is set to last value provided" );
336 error: function(){ ok(false, "error"); }
341 test(".ajax() - contentType" , function() {
355 jQuery.ajax(url("data/headers.php?keys=content-type" ), {
357 success: function( data ) {
358 strictEqual( data , "content-type: test\n" , "Test content-type is sent when options.contentType is set" );
360 complete: function() {
365 jQuery.ajax(url("data/headers.php?keys=content-type" ), {
367 success: function( data ) {
368 strictEqual( data , "content-type: \n" , "Test content-type is not sent when options.contentType===false" );
370 complete: function() {
377 test(".ajax() - hash", function() {
381 url: "data/name.html#foo",
382 beforeSend: function( xhr, settings ) {
383 equals(settings.url, "data/name.html", "Make sure that the URL is trimmed.");
389 url: "data/name.html?abc#foo",
390 beforeSend: function( xhr, settings ) {
391 equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
397 url: "data/name.html?abc#foo",
398 data: { "test": 123 },
399 beforeSend: function( xhr, settings ) {
400 equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed.");
406 test("jQuery ajax - cross-domain detection", function() {
410 var loc = document.location,
411 otherPort = loc.port === 666 ? 667 : 666,
412 otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
416 url: otherProtocol + "//" + loc.host,
417 beforeSend: function( _ , s ) {
418 ok( s.crossDomain , "Test different protocols are detected as cross-domain" );
425 url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
426 beforeSend: function( _ , s ) {
427 ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
434 url: loc.protocol + "//" + loc.hostname + ":" + otherPort,
435 beforeSend: function( _ , s ) {
436 ok( s.crossDomain , "Test different ports are detected as cross-domain" );
443 url: loc.protocol + "//" + loc.host,
445 beforeSend: function( _ , s ) {
446 ok( s.crossDomain , "Test forced crossDomain is detected as cross-domain" );
453 test(".ajax() - 304", function() {
458 url: url("data/notmodified.php"),
459 success: function(){ ok(true, "304 ok"); },
460 // Do this because opera simply refuses to implement 304 handling :(
461 // A feature-driven way of detecting this would be appreciated
462 // See: http://gist.github.com/599419
463 error: function(){ ok(jQuery.browser.opera, "304 not ok "); },
464 complete: function(xhr){ start(); }
468 test(".load()) - 404 error callbacks", function() {
472 jQuery('#foo').ajaxStart(function(){
473 ok( true, "ajaxStart" );
474 }).ajaxStop(function(){
475 ok( true, "ajaxStop" );
477 }).ajaxSend(function(){
478 ok( true, "ajaxSend" );
479 }).ajaxComplete(function(){
480 ok( true, "ajaxComplete" );
481 }).ajaxError(function(){
482 ok( true, "ajaxError" );
483 }).ajaxSuccess(function(){
484 ok( false, "ajaxSuccess" );
487 jQuery("<div/>").load("data/404.html", function(){
488 ok(true, "complete");
492 test("jQuery.ajax() - abort", function() {
496 jQuery('#foo').ajaxStart(function(){
497 ok( true, "ajaxStart" );
498 }).ajaxStop(function(){
499 ok( true, "ajaxStop" );
501 }).ajaxSend(function(){
502 ok( true, "ajaxSend" );
503 }).ajaxComplete(function(){
504 ok( true, "ajaxComplete" );
507 var xhr = jQuery.ajax({
508 url: url("data/name.php?wait=5"),
509 beforeSend: function(){ ok(true, "beforeSend"); },
510 complete: function(){ ok(true, "complete"); }
513 equals( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
516 equals( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
519 test("Ajax events with context", function() {
523 var context = document.createElement("div");
526 equals( this, context, e.type );
529 function callback(msg){
531 equals( this, context, "context is preserved on callback " + msg );
535 function nocallback(msg){
537 equals( typeof this.url, "string", "context is settings on callback " + msg );
541 jQuery('#foo').add(context)
548 url: url("data/name.html"),
549 beforeSend: callback("beforeSend"),
550 success: callback("success"),
551 error: callback("error"),
553 callback("complete").call(this);
556 url: url("data/404.html"),
558 beforeSend: callback("beforeSend"),
559 error: callback("error"),
560 complete: function(){
561 callback("complete").call(this);
563 jQuery('#foo').add(context).unbind();
566 url: url("data/404.html"),
567 beforeSend: nocallback("beforeSend"),
568 error: nocallback("error"),
569 complete: function(){
570 nocallback("complete").call(this);
581 test("jQuery.ajax context modification", function() {
589 url: url("data/name.html"),
591 beforeSend: function(){
594 complete: function() {
599 equals( obj.test, "foo", "Make sure the original object is maintained." );
602 test("jQuery.ajax() - disabled globals", function() {
606 jQuery('#foo').ajaxStart(function(){
607 ok( false, "ajaxStart" );
608 }).ajaxStop(function(){
609 ok( false, "ajaxStop" );
610 }).ajaxSend(function(){
611 ok( false, "ajaxSend" );
612 }).ajaxComplete(function(){
613 ok( false, "ajaxComplete" );
614 }).ajaxError(function(){
615 ok( false, "ajaxError" );
616 }).ajaxSuccess(function(){
617 ok( false, "ajaxSuccess" );
622 url: url("data/name.html"),
623 beforeSend: function(){ ok(true, "beforeSend"); },
624 success: function(){ ok(true, "success"); },
625 error: function(){ ok(false, "error"); },
626 complete: function(){
627 ok(true, "complete");
628 setTimeout(function(){ start(); }, 13);
633 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
637 url: url("data/with_fries.xml"),
639 success: function(resp) {
640 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
641 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
642 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
648 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over JSONP)", function() {
652 url: url("data/with_fries_over_jsonp.php"),
653 dataType: "jsonp xml",
654 success: function(resp) {
655 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
656 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
657 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
660 error: function(_1,_2,error) {
667 test("jQuery.ajax - HEAD requests", function() {
672 url: url("data/name.html"),
674 success: function(data, status, xhr){
675 var h = xhr.getAllResponseHeaders();
676 ok( /Date/i.test(h), 'No Date in HEAD response' );
679 url: url("data/name.html"),
680 data: { whip_it: "good" },
682 success: function(data, status, xhr){
683 var h = xhr.getAllResponseHeaders();
684 ok( /Date/i.test(h), 'No Date in HEAD response with data' );
693 test("jQuery.ajax - beforeSend", function() {
699 jQuery.ajaxSetup({ timeout: 0 });
702 url: url("data/name.html"),
703 beforeSend: function(xml) {
706 success: function(data) {
707 ok( check, "check beforeSend was executed" );
713 test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
715 var request = jQuery.ajax({
716 url: url("data/name.html"),
717 beforeSend: function() {
718 ok( true, "beforeSend got called, canceling" );
721 success: function() {
722 ok( false, "request didn't get canceled" );
724 complete: function() {
725 ok( false, "request didn't get canceled" );
728 ok( false, "request didn't get canceled" );
731 ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
734 test("jQuery.ajax - beforeSend, cancel request manually", function() {
736 var request = jQuery.ajax({
737 url: url("data/name.html"),
738 beforeSend: function(xhr) {
739 ok( true, "beforeSend got called, canceling" );
742 success: function() {
743 ok( false, "request didn't get canceled" );
745 complete: function() {
746 ok( false, "request didn't get canceled" );
749 ok( false, "request didn't get canceled" );
752 ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
755 window.foobar = null;
756 window.testFoo = undefined;
758 test("jQuery.ajax - dataType html", function() {
762 var verifyEvaluation = function() {
763 equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
764 equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
771 url: url("data/test.html"),
772 success: function(data) {
773 jQuery("#ap").html(data);
774 ok( data.match(/^html text/), 'Check content for datatype html' );
775 setTimeout(verifyEvaluation, 600);
780 test("serialize()", function() {
783 // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
784 jQuery("#search").after(
785 '<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+
786 '<input type="number" id="html5number" name="number" value="43" />'
789 equals( jQuery('#form').serialize(),
790 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
791 'Check form serialization as query string');
793 equals( jQuery('#form :input').serialize(),
794 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
795 'Check input serialization as query string');
797 equals( jQuery('#testForm').serialize(),
798 'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
799 'Check form serialization as query string');
801 equals( jQuery('#testForm :input').serialize(),
802 'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
803 'Check input serialization as query string');
805 equals( jQuery('#form, #testForm').serialize(),
806 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
807 'Multiple form serialization as query string');
809 /* Temporarily disabled. Opera 10 has problems with form serialization.
810 equals( jQuery('#form, #testForm :input').serialize(),
811 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
812 'Mixed form/input serialization as query string');
814 jQuery("#html5email, #html5number").remove();
817 test("jQuery.param()", function() {
820 equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
822 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
823 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
825 params = {someName: [1, 2, 3], regularThing: "blah" };
826 equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" );
828 params = {foo: ['a', 'b', 'c']};
829 equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
831 params = {foo: ["baz", 42, "All your base are belong to us"] };
832 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
834 params = {foo: { bar: 'baz', beep: 42, quux: 'All your base are belong to us' } };
835 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" );
837 params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
838 equals( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure" );
840 params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
841 equals( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
843 params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
844 equals( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
846 equals( decodeURIComponent( jQuery.param({ a: [1,2,3], 'b[]': [4,5,6], 'c[d]': [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
848 // Make sure empty arrays and objects are handled #6481
849 equals( jQuery.param({"foo": {"bar": []} }), "foo%5Bbar%5D=", "Empty array param" );
850 equals( jQuery.param({"foo": {"bar": [], foo: 1} }), "foo%5Bbar%5D=&foo%5Bfoo%5D=1", "Empty array param" );
851 equals( jQuery.param({"foo": {"bar": {}} }), "foo%5Bbar%5D=", "Empty object param" );
853 jQuery.ajaxSetup({ traditional: true });
855 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
856 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
858 params = {someName: [1, 2, 3], regularThing: "blah" };
859 equals( jQuery.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" );
861 params = {foo: ['a', 'b', 'c']};
862 equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
864 params = {"foo[]":["baz", 42, "All your base are belong to us"]};
865 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
867 params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
868 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" );
870 params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
871 equals( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure" );
873 params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
874 equals( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
876 params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
877 equals( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
879 params = { param1: null };
880 equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
883 test("synchronous request", function() {
885 ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );
888 test("synchronous request with callbacks", function() {
891 jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } });
892 ok( /^{ "data"/.test( result ), "check returned text" );
895 test("pass-through request object", function() {
899 var target = "data/name.html";
900 var successCount = 0;
903 var success = function() {
906 jQuery("#foo").ajaxError(function (e, xml, s, ex) {
908 errorEx += ": " + xml.status;
910 jQuery("#foo").one('ajaxStop', function () {
911 equals(successCount, 5, "Check all ajax calls successful");
912 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
913 jQuery("#foo").unbind('ajaxError');
918 ok( jQuery.get(url(target), success), "get" );
919 ok( jQuery.post(url(target), success), "post" );
920 ok( jQuery.getScript(url("data/test.js"), success), "script" );
921 ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
922 ok( jQuery.ajax({url: url(target), success: success}), "generic" );
925 test("ajax cache", function () {
932 jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
933 var re = /_=(.*?)(&|$)/g;
935 for (var i = 0; i < 6; i++) {
936 var ret = re.exec(s.url);
942 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
943 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
948 ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
949 ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
950 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
951 ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
952 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
953 ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
958 * The assertions expect that the passed-in object will be modified,
959 * which shouldn't be the case. Fixes #5439.
960 test("global ajaxSettings", function() {
963 var tmp = jQuery.extend({}, jQuery.ajaxSettings);
964 var orig = { url: "data/with_fries.xml" };
967 jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
969 t = jQuery.extend({}, orig);
972 ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
974 t = jQuery.extend({}, orig);
975 t.data = { zoo: 'a', ping: 'b' };
977 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' }" );
979 jQuery.ajaxSettings = tmp;
983 test("load(String)", function() {
985 stop(); // check if load can be called with only url
986 jQuery('#first').load("data/name.html", start);
989 test("load('url selector')", function() {
991 stop(); // check if load can be called with only url
992 jQuery('#first').load("data/test3.html div.user", function(){
993 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
998 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
1001 jQuery.ajaxSetup({ dataType: "json" });
1002 jQuery("#first").ajaxComplete(function (e, xml, s) {
1003 equals( s.dataType, "html", "Verify the load() dataType was html" );
1004 jQuery("#first").unbind("ajaxComplete");
1005 jQuery.ajaxSetup({ dataType: "" });
1008 jQuery('#first').load("data/test3.html");
1011 test("load(String, Function) - simple: inject text into DOM", function() {
1014 jQuery('#first').load(url("data/name.html"), function() {
1015 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
1020 test("load(String, Function) - check scripts", function() {
1024 var verifyEvaluation = function() {
1025 equals( foobar, "bar", 'Check if script src was evaluated after load' );
1026 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
1030 jQuery('#first').load(url('data/test.html'), function() {
1031 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
1032 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1033 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1034 setTimeout(verifyEvaluation, 600);
1038 test("load(String, Function) - check file with only a script tag", function() {
1042 jQuery('#first').load(url('data/test2.html'), function() {
1043 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1044 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1050 test("load(String, Function) - dataFilter in ajaxSettings", function() {
1053 jQuery.ajaxSetup({ dataFilter: function() { return "Hello World"; } });
1054 var div = jQuery("<div/>").load(url("data/name.html"), function(responseText) {
1055 strictEqual( div.html(), "Hello World" , "Test div was filled with filtered data" );
1056 strictEqual( responseText, "Hello World" , "Test callback receives filtered data" );
1057 jQuery.ajaxSetup({ dataFilter: 0 });
1062 test("load(String, Object, Function)", function() {
1066 jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
1067 var $post = jQuery(this).find('#post');
1068 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
1069 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
1074 test("load(String, String, Function)", function() {
1078 jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
1079 var $get = jQuery(this).find('#get');
1080 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
1081 equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly');
1086 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
1089 jQuery.get(url('data/dashboard.xml'), function(xml) {
1091 jQuery('tab', xml).each(function() {
1092 content.push(jQuery(this).text());
1094 equals( content[0], 'blabla', 'Check first tab');
1095 equals( content[1], 'blublu', 'Check second tab');
1100 test("jQuery.getScript(String, Function) - with callback", function() {
1103 jQuery.getScript(url("data/test.js"), function() {
1104 equals( foobar, "bar", 'Check if script was evaluated' );
1105 setTimeout(start, 100);
1109 test("jQuery.getScript(String, Function) - no callback", function() {
1112 jQuery.getScript(url("data/test.js"), function(){
1117 jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) {
1119 test("jQuery.ajax() - JSONP, " + label, function() {
1123 function plus(){ if ( ++count == 17 ) start(); }
1128 url: "data/jsonp.php",
1130 crossDomain: crossDomain,
1131 success: function(data){
1132 ok( data.data, "JSON results returned (GET, no callback)" );
1135 error: function(data){
1136 ok( false, "Ajax error JSON (GET, no callback)" );
1142 url: "data/jsonp.php?callback=?",
1144 crossDomain: crossDomain,
1145 success: function(data){
1146 ok( data.data, "JSON results returned (GET, url callback)" );
1149 error: function(data){
1150 ok( false, "Ajax error JSON (GET, url callback)" );
1156 url: "data/jsonp.php",
1158 crossDomain: crossDomain,
1160 success: function(data){
1161 ok( data.data, "JSON results returned (GET, data callback)" );
1164 error: function(data){
1165 ok( false, "Ajax error JSON (GET, data callback)" );
1171 url: "data/jsonp.php?callback=??",
1173 crossDomain: crossDomain,
1174 success: function(data){
1175 ok( data.data, "JSON results returned (GET, url context-free callback)" );
1178 error: function(data){
1179 ok( false, "Ajax error JSON (GET, url context-free callback)" );
1185 url: "data/jsonp.php",
1187 crossDomain: crossDomain,
1188 data: "callback=??",
1189 success: function(data){
1190 ok( data.data, "JSON results returned (GET, data context-free callback)" );
1193 error: function(data){
1194 ok( false, "Ajax error JSON (GET, data context-free callback)" );
1200 url: "data/jsonp.php/??",
1202 crossDomain: crossDomain,
1203 success: function(data){
1204 ok( data.data, "JSON results returned (GET, REST-like)" );
1207 error: function(data){
1208 ok( false, "Ajax error JSON (GET, REST-like)" );
1214 url: "data/jsonp.php/???json=1",
1216 crossDomain: crossDomain,
1217 success: function(data){
1218 strictEqual( jQuery.type(data), "array", "JSON results returned (GET, REST-like with param)" );
1221 error: function(data){
1222 ok( false, "Ajax error JSON (GET, REST-like with param)" );
1228 url: "data/jsonp.php",
1230 crossDomain: crossDomain,
1234 success: function(data){
1235 ok( data.data, "JSON results returned (GET, processed data callback)" );
1238 error: function(data){
1239 ok( false, "Ajax error JSON (GET, processed data callback)" );
1245 url: "data/jsonp.php",
1247 crossDomain: crossDomain,
1249 success: function(data){
1250 ok( data.data, "JSON results returned (GET, data obj callback)" );
1253 error: function(data){
1254 ok( false, "Ajax error JSON (GET, data obj callback)" );
1259 window.jsonpResults = function(data) {
1260 ok( data.data, "JSON results returned (GET, custom callback function)" );
1261 window.jsonpResults = undefined;
1266 url: "data/jsonp.php",
1268 crossDomain: crossDomain,
1269 jsonpCallback: "jsonpResults",
1270 success: function(data){
1271 ok( data.data, "JSON results returned (GET, custom callback name)" );
1274 error: function(data){
1275 ok( false, "Ajax error JSON (GET, custom callback name)" );
1282 url: "data/jsonp.php",
1284 crossDomain: crossDomain,
1285 success: function(data){
1286 ok( data.data, "JSON results returned (POST, no callback)" );
1289 error: function(data){
1290 ok( false, "Ajax error JSON (GET, data obj callback)" );
1297 url: "data/jsonp.php",
1300 crossDomain: crossDomain,
1301 success: function(data){
1302 ok( data.data, "JSON results returned (POST, data callback)" );
1305 error: function(data){
1306 ok( false, "Ajax error JSON (POST, data callback)" );
1313 url: "data/jsonp.php",
1316 crossDomain: crossDomain,
1317 success: function(data){
1318 ok( data.data, "JSON results returned (POST, data obj callback)" );
1321 error: function(data){
1322 ok( false, "Ajax error JSON (POST, data obj callback)" );
1329 url: "data/jsonp.php",
1331 crossDomain: crossDomain,
1332 beforeSend: function(){
1333 strictEqual( this.cache, false, "cache must be false on JSON request" );
1340 url: "data/jsonp.php?callback=XXX",
1343 jsonpCallback: "XXX",
1344 crossDomain: crossDomain,
1345 beforeSend: function() {
1346 ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ) ,
1347 "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
1350 success: function(data){
1351 ok( data.data, "JSON results returned (GET, custom callback name with no url manipulation)" );
1354 error: function(data){
1355 ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
1363 test("jQuery.ajax() - script, Remote", function() {
1366 var base = window.location.href.replace(/[^\/]*$/, "");
1371 url: base + "data/test.js",
1373 success: function(data){
1374 ok( foobar, "Script results returned (GET, no callback)" );
1380 test("jQuery.ajax() - script, Remote with POST", function() {
1383 var base = window.location.href.replace(/[^\/]*$/, "");
1388 url: base + "data/test.js",
1391 success: function(data, status){
1392 ok( foobar, "Script results returned (POST, no callback)" );
1393 equals( status, "success", "Script results returned (POST, no callback)" );
1396 error: function(xhr) {
1397 ok( false, "ajax error, status code: " + xhr.status );
1403 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
1406 var base = window.location.href.replace(/[^\/]*$/, "");
1407 base = base.replace(/^.*?\/\//, "//");
1412 url: base + "data/test.js",
1414 success: function(data){
1415 ok( foobar, "Script results returned (GET, no callback)" );
1421 test("jQuery.ajax() - malformed JSON", function() {
1427 url: "data/badjson.js",
1429 success: function(){
1430 ok( false, "Success." );
1433 error: function(xhr, msg, detailedMsg) {
1434 equals( "parsererror", msg, "A parse error occurred." );
1435 ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" );
1441 test("jQuery.ajax() - script by content-type", function() {
1447 url: "data/script.php",
1448 data: { header: "script" },
1449 success: function() {
1455 test("jQuery.ajax() - json by content-type", function() {
1461 url: "data/json.php",
1462 data: { header: "json", json: "array" },
1463 success: function( json ) {
1464 ok( json.length >= 2, "Check length");
1465 equals( json[0].name, 'John', 'Check JSON: first, name' );
1466 equals( json[0].age, 21, 'Check JSON: first, age' );
1467 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1468 equals( json[1].age, 25, 'Check JSON: second, age' );
1474 test("jQuery.ajax() - json by content-type disabled with options", function() {
1480 url: url("data/json.php"),
1481 data: { header: "json", json: "array" },
1485 success: function( text ) {
1486 equals( typeof text , "string" , "json wasn't auto-determined" );
1487 var json = jQuery.parseJSON( text );
1488 ok( json.length >= 2, "Check length");
1489 equals( json[0].name, 'John', 'Check JSON: first, name' );
1490 equals( json[0].age, 21, 'Check JSON: first, age' );
1491 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1492 equals( json[1].age, 25, 'Check JSON: second, age' );
1498 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
1501 jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
1502 ok( json.length >= 2, "Check length");
1503 equals( json[0].name, 'John', 'Check JSON: first, name' );
1504 equals( json[0].age, 21, 'Check JSON: first, age' );
1505 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1506 equals( json[1].age, 25, 'Check JSON: second, age' );
1511 test("jQuery.getJSON(String, Function) - JSON object", function() {
1514 jQuery.getJSON(url("data/json.php"), function(json) {
1515 if (json && json.data) {
1516 equals( json.data.lang, 'en', 'Check JSON: lang' );
1517 equals( json.data.length, 25, 'Check JSON: length' );
1523 test("jQuery.getJSON - Using Native JSON", function() {
1526 var old = window.JSON;
1528 parse: function(str){
1529 ok( true, "Verifying that parse method was run" );
1535 jQuery.getJSON(url("data/json.php"), function(json) {
1537 equals( json, true, "Verifying return value" );
1542 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
1545 var base = window.location.href.replace(/[^\/]*$/, "");
1548 jQuery.getJSON(url(base + "data/json.php"), function(json) {
1549 equals( json.data.lang, 'en', 'Check JSON: lang' );
1550 equals( json.data.length, 25, 'Check JSON: length' );
1555 test("jQuery.post - data", function() {
1559 jQuery.post(url("data/name.php"), {xml: "5-2", length: 3}, function(xml){
1560 jQuery('math', xml).each(function() {
1561 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1562 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1568 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
1573 jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
1574 jQuery('math', xml).each(function() {
1575 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1576 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1578 if ( ++done === 2 ) start();
1581 jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
1582 jQuery('math', xml).each(function() {
1583 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1584 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1586 if ( ++done === 2 ) start();
1590 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
1595 jQuery.ajaxSetup({timeout: 1000});
1597 var pass = function() {
1599 if ( passed == 2 ) {
1600 ok( true, 'Check local and global callbacks after timeout' );
1601 jQuery('#main').unbind("ajaxError");
1606 var fail = function(a,b,c) {
1607 ok( false, 'Check for timeout failed ' + a + ' ' + b );
1611 jQuery('#main').ajaxError(pass);
1615 url: url("data/name.php?wait=5"),
1621 jQuery.ajaxSetup({timeout: 0});
1624 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
1626 jQuery.ajaxSetup({timeout: 50});
1631 url: url("data/name.php?wait=1"),
1633 ok( false, 'Check for local timeout failed' );
1636 success: function() {
1637 ok( true, 'Check for local timeout' );
1643 jQuery.ajaxSetup({timeout: 0});
1646 test("jQuery.ajax - simple get", function() {
1651 url: url("data/name.php?name=foo"),
1652 success: function(msg){
1653 equals( msg, 'bar', 'Check for GET' );
1659 test("jQuery.ajax - simple post", function() {
1664 url: url("data/name.php"),
1666 success: function(msg){
1667 equals( msg, 'pan', 'Check for POST' );
1673 test("ajaxSetup()", function() {
1677 url: url("data/name.php?name=foo"),
1678 success: function(msg){
1679 equals( msg, 'bar', 'Check for GET' );
1687 test("custom timeout does not set error message when timeout occurs, see #970", function() {
1690 url: "data/name.php?wait=1",
1692 error: function(request, status) {
1693 ok( status != null, "status shouldn't be null in error handler" );
1694 equals( "timeout", status );
1701 test("data option: evaluate function values (#2806)", function() {
1704 url: "data/echoQuery.php",
1710 success: function(result) {
1711 equals( result, "key=value" );
1717 test("data option: empty bodies for non-GET requests", function() {
1720 url: "data/echoData.php",
1723 success: function(result) {
1724 equals( result, "" );
1730 test("jQuery.ajax - If-Modified-Since support", function() {
1735 var url = "data/if_modified_since.php?ts=" + new Date();
1740 success: function(data, status) {
1741 equals(status, "success");
1746 success: function(data, status) {
1747 if ( data === "FAIL" ) {
1748 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1749 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1751 equals(status, "notmodified");
1752 ok(data == null, "response body should be empty");
1757 // Do this because opera simply refuses to implement 304 handling :(
1758 // A feature-driven way of detecting this would be appreciated
1759 // See: http://gist.github.com/599419
1760 ok(jQuery.browser.opera, "error");
1761 ok(jQuery.browser.opera, "error");
1767 equals(false, "error");
1768 // Do this because opera simply refuses to implement 304 handling :(
1769 // A feature-driven way of detecting this would be appreciated
1770 // See: http://gist.github.com/599419
1771 ok(jQuery.browser.opera, "error");
1777 test("jQuery.ajax - Etag support", function() {
1782 var url = "data/etag.php?ts=" + new Date();
1787 success: function(data, status) {
1788 equals(status, "success");
1793 success: function(data, status) {
1794 if ( data === "FAIL" ) {
1795 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1796 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1798 equals(status, "notmodified");
1799 ok(data == null, "response body should be empty");
1804 // Do this because opera simply refuses to implement 304 handling :(
1805 // A feature-driven way of detecting this would be appreciated
1806 // See: http://gist.github.com/599419
1807 ok(jQuery.browser.opera, "error");
1808 ok(jQuery.browser.opera, "error");
1814 // Do this because opera simply refuses to implement 304 handling :(
1815 // A feature-driven way of detecting this would be appreciated
1816 // See: http://gist.github.com/599419
1817 ok(jQuery.browser.opera, "error");
1823 test("jQuery ajax - failing cross-domain", function() {
1832 url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
1833 success: function(){ ok( false , "success" ); },
1834 error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
1835 complete: function() { if ( ! --i ) start(); }
1839 url: 'http://www.google.com',
1840 success: function(){ ok( false , "success" ); },
1841 error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
1842 complete: function() { if ( ! --i ) start(); }
1847 test("jQuery ajax - atom+xml", function() {
1852 url: url( 'data/atom+xml.php' ),
1853 success: function(){ ok( true , "success" ); },
1854 error: function(){ ok( false , "error" ); },
1855 complete: function() { start(); }
1860 test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
1861 var success = false;
1863 var xhr = jQuery.ajax({ url: window.location });
1868 ok( success, "document.location did not generate exception" );
1871 test( "jQuery.ajax - statusCode" , function() {
1878 function countComplete() {
1884 function createStatusCodes( name , isSuccess ) {
1885 name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
1888 ok( isSuccess , name );
1891 ok( ! isSuccess , name );
1897 "data/name.html": true,
1898 "data/someFileThatDoesNotExist.html": false
1899 } , function( uri , isSuccess ) {
1901 jQuery.ajax( url( uri ) , {
1902 statusCode: createStatusCodes( "in options" , isSuccess ),
1903 complete: countComplete
1906 jQuery.ajax( url( uri ) , {
1907 complete: countComplete
1908 }).statusCode( createStatusCodes( "immediately with method" , isSuccess ) );
1910 jQuery.ajax( url( uri ) , {
1911 complete: function(jXHR) {
1912 jXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) );
1917 jQuery.ajax( url( uri ) , {
1918 complete: function(jXHR) {
1919 setTimeout( function() {
1920 jXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) );
1926 jQuery.ajax( url( uri ) , {
1927 statusCode: createStatusCodes( "all (options)" , isSuccess ),
1928 complete: function(jXHR) {
1929 jXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) );
1930 setTimeout( function() {
1931 jXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) );
1935 }).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) );
1941 test("jQuery.ajax - active counter", function() {
1942 ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );