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 context modification through ajaxSetup", function() {
613 strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." );
616 url: url("data/name.html"),
617 complete: function() {
618 strictEqual( this, obj, "Make sure the original object is maintained." );
620 url: url("data/name.html"),
622 complete: function() {
623 ok( this !== obj, "Make sure overidding context is possible." );
628 url: url("data/name.html"),
629 beforeSend: function(){
632 complete: function() {
633 ok( this !== obj, "Make sure unsetting context is possible." );
643 test("jQuery.ajax() - disabled globals", function() {
647 jQuery('#foo').ajaxStart(function(){
648 ok( false, "ajaxStart" );
649 }).ajaxStop(function(){
650 ok( false, "ajaxStop" );
651 }).ajaxSend(function(){
652 ok( false, "ajaxSend" );
653 }).ajaxComplete(function(){
654 ok( false, "ajaxComplete" );
655 }).ajaxError(function(){
656 ok( false, "ajaxError" );
657 }).ajaxSuccess(function(){
658 ok( false, "ajaxSuccess" );
663 url: url("data/name.html"),
664 beforeSend: function(){ ok(true, "beforeSend"); },
665 success: function(){ ok(true, "success"); },
666 error: function(){ ok(false, "error"); },
667 complete: function(){
668 ok(true, "complete");
669 setTimeout(function(){ start(); }, 13);
674 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
678 url: url("data/with_fries.xml"),
680 success: function(resp) {
681 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
682 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
683 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
689 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over JSONP)", function() {
693 url: url("data/with_fries_over_jsonp.php"),
694 dataType: "jsonp xml",
695 success: function(resp) {
696 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
697 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
698 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
701 error: function(_1,_2,error) {
708 test("jQuery.ajax - HEAD requests", function() {
713 url: url("data/name.html"),
715 success: function(data, status, xhr){
716 var h = xhr.getAllResponseHeaders();
717 ok( /Date/i.test(h), 'No Date in HEAD response' );
720 url: url("data/name.html"),
721 data: { whip_it: "good" },
723 success: function(data, status, xhr){
724 var h = xhr.getAllResponseHeaders();
725 ok( /Date/i.test(h), 'No Date in HEAD response with data' );
734 test("jQuery.ajax - beforeSend", function() {
740 jQuery.ajaxSetup({ timeout: 0 });
743 url: url("data/name.html"),
744 beforeSend: function(xml) {
747 success: function(data) {
748 ok( check, "check beforeSend was executed" );
754 test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
756 var request = jQuery.ajax({
757 url: url("data/name.html"),
758 beforeSend: function() {
759 ok( true, "beforeSend got called, canceling" );
762 success: function() {
763 ok( false, "request didn't get canceled" );
765 complete: function() {
766 ok( false, "request didn't get canceled" );
769 ok( false, "request didn't get canceled" );
772 ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
775 test("jQuery.ajax - beforeSend, cancel request manually", function() {
777 var request = jQuery.ajax({
778 url: url("data/name.html"),
779 beforeSend: function(xhr) {
780 ok( true, "beforeSend got called, canceling" );
783 success: function() {
784 ok( false, "request didn't get canceled" );
786 complete: function() {
787 ok( false, "request didn't get canceled" );
790 ok( false, "request didn't get canceled" );
793 ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
796 window.foobar = null;
797 window.testFoo = undefined;
799 test("jQuery.ajax - dataType html", function() {
803 var verifyEvaluation = function() {
804 equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
805 equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
812 url: url("data/test.html"),
813 success: function(data) {
814 jQuery("#ap").html(data);
815 ok( data.match(/^html text/), 'Check content for datatype html' );
816 setTimeout(verifyEvaluation, 600);
821 test("serialize()", function() {
824 // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
825 jQuery("#search").after(
826 '<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+
827 '<input type="number" id="html5number" name="number" value="43" />'
830 equals( jQuery('#form').serialize(),
831 "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",
832 'Check form serialization as query string');
834 equals( jQuery('#form :input').serialize(),
835 "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",
836 'Check input serialization as query string');
838 equals( jQuery('#testForm').serialize(),
839 'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
840 'Check form serialization as query string');
842 equals( jQuery('#testForm :input').serialize(),
843 'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
844 'Check input serialization as query string');
846 equals( jQuery('#form, #testForm').serialize(),
847 "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=",
848 'Multiple form serialization as query string');
850 /* Temporarily disabled. Opera 10 has problems with form serialization.
851 equals( jQuery('#form, #testForm :input').serialize(),
852 "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=",
853 'Mixed form/input serialization as query string');
855 jQuery("#html5email, #html5number").remove();
858 test("jQuery.param()", function() {
861 equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
863 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
864 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
866 params = {someName: [1, 2, 3], regularThing: "blah" };
867 equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" );
869 params = {foo: ['a', 'b', 'c']};
870 equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
872 params = {foo: ["baz", 42, "All your base are belong to us"] };
873 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
875 params = {foo: { bar: 'baz', beep: 42, quux: 'All your base are belong to us' } };
876 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" );
878 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?" };
879 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" );
881 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 ] };
882 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" );
884 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?" };
885 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" );
887 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." );
889 // Make sure empty arrays and objects are handled #6481
890 equals( jQuery.param({"foo": {"bar": []} }), "foo%5Bbar%5D=", "Empty array param" );
891 equals( jQuery.param({"foo": {"bar": [], foo: 1} }), "foo%5Bbar%5D=&foo%5Bfoo%5D=1", "Empty array param" );
892 equals( jQuery.param({"foo": {"bar": {}} }), "foo%5Bbar%5D=", "Empty object param" );
894 jQuery.ajaxSetup({ traditional: true });
896 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
897 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
899 params = {someName: [1, 2, 3], regularThing: "blah" };
900 equals( jQuery.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" );
902 params = {foo: ['a', 'b', 'c']};
903 equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
905 params = {"foo[]":["baz", 42, "All your base are belong to us"]};
906 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
908 params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
909 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" );
911 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?" };
912 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" );
914 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 ] };
915 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)" );
917 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?" };
918 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" );
920 params = { param1: null };
921 equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
924 test("synchronous request", function() {
926 ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );
929 test("synchronous request with callbacks", function() {
932 jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } });
933 ok( /^{ "data"/.test( result ), "check returned text" );
936 test("pass-through request object", function() {
940 var target = "data/name.html";
941 var successCount = 0;
944 var success = function() {
947 jQuery("#foo").ajaxError(function (e, xml, s, ex) {
949 errorEx += ": " + xml.status;
951 jQuery("#foo").one('ajaxStop', function () {
952 equals(successCount, 5, "Check all ajax calls successful");
953 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
954 jQuery("#foo").unbind('ajaxError');
959 ok( jQuery.get(url(target), success), "get" );
960 ok( jQuery.post(url(target), success), "post" );
961 ok( jQuery.getScript(url("data/test.js"), success), "script" );
962 ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
963 ok( jQuery.ajax({url: url(target), success: success}), "generic" );
966 test("ajax cache", function () {
973 jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
974 var re = /_=(.*?)(&|$)/g;
976 for (var i = 0; i < 6; i++) {
977 var ret = re.exec(s.url);
983 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
984 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
989 ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
990 ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
991 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
992 ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
993 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
994 ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
999 * The assertions expect that the passed-in object will be modified,
1000 * which shouldn't be the case. Fixes #5439.
1001 test("global ajaxSettings", function() {
1004 var tmp = jQuery.extend({}, jQuery.ajaxSettings);
1005 var orig = { url: "data/with_fries.xml" };
1008 jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
1010 t = jQuery.extend({}, orig);
1013 ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
1015 t = jQuery.extend({}, orig);
1016 t.data = { zoo: 'a', ping: 'b' };
1018 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' }" );
1020 jQuery.ajaxSettings = tmp;
1024 test("load(String)", function() {
1026 stop(); // check if load can be called with only url
1027 jQuery('#first').load("data/name.html", start);
1030 test("load('url selector')", function() {
1032 stop(); // check if load can be called with only url
1033 jQuery('#first').load("data/test3.html div.user", function(){
1034 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
1039 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
1042 jQuery.ajaxSetup({ dataType: "json" });
1043 jQuery("#first").ajaxComplete(function (e, xml, s) {
1044 equals( s.dataType, "html", "Verify the load() dataType was html" );
1045 jQuery("#first").unbind("ajaxComplete");
1046 jQuery.ajaxSetup({ dataType: "" });
1049 jQuery('#first').load("data/test3.html");
1052 test("load(String, Function) - simple: inject text into DOM", function() {
1055 jQuery('#first').load(url("data/name.html"), function() {
1056 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
1061 test("load(String, Function) - check scripts", function() {
1065 var verifyEvaluation = function() {
1066 equals( foobar, "bar", 'Check if script src was evaluated after load' );
1067 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
1071 jQuery('#first').load(url('data/test.html'), function() {
1072 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
1073 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1074 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1075 setTimeout(verifyEvaluation, 600);
1079 test("load(String, Function) - check file with only a script tag", function() {
1083 jQuery('#first').load(url('data/test2.html'), function() {
1084 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1085 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1091 test("load(String, Function) - dataFilter in ajaxSettings", function() {
1094 jQuery.ajaxSetup({ dataFilter: function() { return "Hello World"; } });
1095 var div = jQuery("<div/>").load(url("data/name.html"), function(responseText) {
1096 strictEqual( div.html(), "Hello World" , "Test div was filled with filtered data" );
1097 strictEqual( responseText, "Hello World" , "Test callback receives filtered data" );
1098 jQuery.ajaxSetup({ dataFilter: 0 });
1103 test("load(String, Object, Function)", function() {
1107 jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
1108 var $post = jQuery(this).find('#post');
1109 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
1110 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
1115 test("load(String, String, Function)", function() {
1119 jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
1120 var $get = jQuery(this).find('#get');
1121 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
1122 equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly');
1127 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
1130 jQuery.get(url('data/dashboard.xml'), function(xml) {
1132 jQuery('tab', xml).each(function() {
1133 content.push(jQuery(this).text());
1135 equals( content[0], 'blabla', 'Check first tab');
1136 equals( content[1], 'blublu', 'Check second tab');
1141 test("jQuery.getScript(String, Function) - with callback", function() {
1144 jQuery.getScript(url("data/test.js"), function() {
1145 equals( foobar, "bar", 'Check if script was evaluated' );
1146 setTimeout(start, 100);
1150 test("jQuery.getScript(String, Function) - no callback", function() {
1153 jQuery.getScript(url("data/test.js"), function(){
1158 jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) {
1160 test("jQuery.ajax() - JSONP, " + label, function() {
1164 function plus(){ if ( ++count == 17 ) start(); }
1169 url: "data/jsonp.php",
1171 crossDomain: crossDomain,
1172 success: function(data){
1173 ok( data.data, "JSON results returned (GET, no callback)" );
1176 error: function(data){
1177 ok( false, "Ajax error JSON (GET, no callback)" );
1183 url: "data/jsonp.php?callback=?",
1185 crossDomain: crossDomain,
1186 success: function(data){
1187 ok( data.data, "JSON results returned (GET, url callback)" );
1190 error: function(data){
1191 ok( false, "Ajax error JSON (GET, url callback)" );
1197 url: "data/jsonp.php",
1199 crossDomain: crossDomain,
1201 success: function(data){
1202 ok( data.data, "JSON results returned (GET, data callback)" );
1205 error: function(data){
1206 ok( false, "Ajax error JSON (GET, data callback)" );
1212 url: "data/jsonp.php?callback=??",
1214 crossDomain: crossDomain,
1215 success: function(data){
1216 ok( data.data, "JSON results returned (GET, url context-free callback)" );
1219 error: function(data){
1220 ok( false, "Ajax error JSON (GET, url context-free callback)" );
1226 url: "data/jsonp.php",
1228 crossDomain: crossDomain,
1229 data: "callback=??",
1230 success: function(data){
1231 ok( data.data, "JSON results returned (GET, data context-free callback)" );
1234 error: function(data){
1235 ok( false, "Ajax error JSON (GET, data context-free callback)" );
1241 url: "data/jsonp.php/??",
1243 crossDomain: crossDomain,
1244 success: function(data){
1245 ok( data.data, "JSON results returned (GET, REST-like)" );
1248 error: function(data){
1249 ok( false, "Ajax error JSON (GET, REST-like)" );
1255 url: "data/jsonp.php/???json=1",
1257 crossDomain: crossDomain,
1258 success: function(data){
1259 strictEqual( jQuery.type(data), "array", "JSON results returned (GET, REST-like with param)" );
1262 error: function(data){
1263 ok( false, "Ajax error JSON (GET, REST-like with param)" );
1269 url: "data/jsonp.php",
1271 crossDomain: crossDomain,
1275 success: function(data){
1276 ok( data.data, "JSON results returned (GET, processed data callback)" );
1279 error: function(data){
1280 ok( false, "Ajax error JSON (GET, processed data callback)" );
1286 url: "data/jsonp.php",
1288 crossDomain: crossDomain,
1290 success: function(data){
1291 ok( data.data, "JSON results returned (GET, data obj callback)" );
1294 error: function(data){
1295 ok( false, "Ajax error JSON (GET, data obj callback)" );
1300 window.jsonpResults = function(data) {
1301 ok( data.data, "JSON results returned (GET, custom callback function)" );
1302 window.jsonpResults = undefined;
1307 url: "data/jsonp.php",
1309 crossDomain: crossDomain,
1310 jsonpCallback: "jsonpResults",
1311 success: function(data){
1312 ok( data.data, "JSON results returned (GET, custom callback name)" );
1315 error: function(data){
1316 ok( false, "Ajax error JSON (GET, custom callback name)" );
1323 url: "data/jsonp.php",
1325 crossDomain: crossDomain,
1326 success: function(data){
1327 ok( data.data, "JSON results returned (POST, no callback)" );
1330 error: function(data){
1331 ok( false, "Ajax error JSON (GET, data obj callback)" );
1338 url: "data/jsonp.php",
1341 crossDomain: crossDomain,
1342 success: function(data){
1343 ok( data.data, "JSON results returned (POST, data callback)" );
1346 error: function(data){
1347 ok( false, "Ajax error JSON (POST, data callback)" );
1354 url: "data/jsonp.php",
1357 crossDomain: crossDomain,
1358 success: function(data){
1359 ok( data.data, "JSON results returned (POST, data obj callback)" );
1362 error: function(data){
1363 ok( false, "Ajax error JSON (POST, data obj callback)" );
1370 url: "data/jsonp.php",
1372 crossDomain: crossDomain,
1373 beforeSend: function(){
1374 strictEqual( this.cache, false, "cache must be false on JSON request" );
1381 url: "data/jsonp.php?callback=XXX",
1384 jsonpCallback: "XXX",
1385 crossDomain: crossDomain,
1386 beforeSend: function() {
1387 ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ) ,
1388 "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
1391 success: function(data){
1392 ok( data.data, "JSON results returned (GET, custom callback name with no url manipulation)" );
1395 error: function(data){
1396 ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
1404 test("jQuery.ajax() - script, Remote", function() {
1407 var base = window.location.href.replace(/[^\/]*$/, "");
1412 url: base + "data/test.js",
1414 success: function(data){
1415 ok( foobar, "Script results returned (GET, no callback)" );
1421 test("jQuery.ajax() - script, Remote with POST", function() {
1424 var base = window.location.href.replace(/[^\/]*$/, "");
1429 url: base + "data/test.js",
1432 success: function(data, status){
1433 ok( foobar, "Script results returned (POST, no callback)" );
1434 equals( status, "success", "Script results returned (POST, no callback)" );
1437 error: function(xhr) {
1438 ok( false, "ajax error, status code: " + xhr.status );
1444 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
1447 var base = window.location.href.replace(/[^\/]*$/, "");
1448 base = base.replace(/^.*?\/\//, "//");
1453 url: base + "data/test.js",
1455 success: function(data){
1456 ok( foobar, "Script results returned (GET, no callback)" );
1462 test("jQuery.ajax() - malformed JSON", function() {
1468 url: "data/badjson.js",
1470 success: function(){
1471 ok( false, "Success." );
1474 error: function(xhr, msg, detailedMsg) {
1475 equals( "parsererror", msg, "A parse error occurred." );
1476 ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" );
1482 test("jQuery.ajax() - script by content-type", function() {
1488 url: "data/script.php",
1489 data: { header: "script" },
1490 success: function() {
1496 test("jQuery.ajax() - json by content-type", function() {
1502 url: "data/json.php",
1503 data: { header: "json", json: "array" },
1504 success: function( json ) {
1505 ok( json.length >= 2, "Check length");
1506 equals( json[0].name, 'John', 'Check JSON: first, name' );
1507 equals( json[0].age, 21, 'Check JSON: first, age' );
1508 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1509 equals( json[1].age, 25, 'Check JSON: second, age' );
1515 test("jQuery.ajax() - json by content-type disabled with options", function() {
1521 url: url("data/json.php"),
1522 data: { header: "json", json: "array" },
1526 success: function( text ) {
1527 equals( typeof text , "string" , "json wasn't auto-determined" );
1528 var json = jQuery.parseJSON( text );
1529 ok( json.length >= 2, "Check length");
1530 equals( json[0].name, 'John', 'Check JSON: first, name' );
1531 equals( json[0].age, 21, 'Check JSON: first, age' );
1532 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1533 equals( json[1].age, 25, 'Check JSON: second, age' );
1539 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
1542 jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
1543 ok( json.length >= 2, "Check length");
1544 equals( json[0].name, 'John', 'Check JSON: first, name' );
1545 equals( json[0].age, 21, 'Check JSON: first, age' );
1546 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1547 equals( json[1].age, 25, 'Check JSON: second, age' );
1552 test("jQuery.getJSON(String, Function) - JSON object", function() {
1555 jQuery.getJSON(url("data/json.php"), function(json) {
1556 if (json && json.data) {
1557 equals( json.data.lang, 'en', 'Check JSON: lang' );
1558 equals( json.data.length, 25, 'Check JSON: length' );
1564 test("jQuery.getJSON - Using Native JSON", function() {
1567 var old = window.JSON;
1569 parse: function(str){
1570 ok( true, "Verifying that parse method was run" );
1576 jQuery.getJSON(url("data/json.php"), function(json) {
1578 equals( json, true, "Verifying return value" );
1583 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
1586 var base = window.location.href.replace(/[^\/]*$/, "");
1589 jQuery.getJSON(url(base + "data/json.php"), function(json) {
1590 equals( json.data.lang, 'en', 'Check JSON: lang' );
1591 equals( json.data.length, 25, 'Check JSON: length' );
1596 test("jQuery.post - data", function() {
1600 jQuery.post(url("data/name.php"), {xml: "5-2", length: 3}, function(xml){
1601 jQuery('math', xml).each(function() {
1602 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1603 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1609 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
1614 jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
1615 jQuery('math', xml).each(function() {
1616 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1617 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1619 if ( ++done === 2 ) start();
1622 jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
1623 jQuery('math', xml).each(function() {
1624 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1625 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1627 if ( ++done === 2 ) start();
1631 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
1636 jQuery.ajaxSetup({timeout: 1000});
1638 var pass = function() {
1640 if ( passed == 2 ) {
1641 ok( true, 'Check local and global callbacks after timeout' );
1642 jQuery('#main').unbind("ajaxError");
1647 var fail = function(a,b,c) {
1648 ok( false, 'Check for timeout failed ' + a + ' ' + b );
1652 jQuery('#main').ajaxError(pass);
1656 url: url("data/name.php?wait=5"),
1662 jQuery.ajaxSetup({timeout: 0});
1665 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
1667 jQuery.ajaxSetup({timeout: 50});
1672 url: url("data/name.php?wait=1"),
1674 ok( false, 'Check for local timeout failed' );
1677 success: function() {
1678 ok( true, 'Check for local timeout' );
1684 jQuery.ajaxSetup({timeout: 0});
1687 test("jQuery.ajax - simple get", function() {
1692 url: url("data/name.php?name=foo"),
1693 success: function(msg){
1694 equals( msg, 'bar', 'Check for GET' );
1700 test("jQuery.ajax - simple post", function() {
1705 url: url("data/name.php"),
1707 success: function(msg){
1708 equals( msg, 'pan', 'Check for POST' );
1714 test("ajaxSetup()", function() {
1718 url: url("data/name.php?name=foo"),
1719 success: function(msg){
1720 equals( msg, 'bar', 'Check for GET' );
1728 test("custom timeout does not set error message when timeout occurs, see #970", function() {
1731 url: "data/name.php?wait=1",
1733 error: function(request, status) {
1734 ok( status != null, "status shouldn't be null in error handler" );
1735 equals( "timeout", status );
1742 test("data option: evaluate function values (#2806)", function() {
1745 url: "data/echoQuery.php",
1751 success: function(result) {
1752 equals( result, "key=value" );
1758 test("data option: empty bodies for non-GET requests", function() {
1761 url: "data/echoData.php",
1764 success: function(result) {
1765 equals( result, "" );
1771 test("jQuery.ajax - If-Modified-Since support", function() {
1776 var url = "data/if_modified_since.php?ts=" + new Date();
1781 success: function(data, status) {
1782 equals(status, "success");
1787 success: function(data, status) {
1788 if ( data === "FAIL" ) {
1789 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1790 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1792 equals(status, "notmodified");
1793 ok(data == null, "response body should be empty");
1798 // Do this because opera simply refuses to implement 304 handling :(
1799 // A feature-driven way of detecting this would be appreciated
1800 // See: http://gist.github.com/599419
1801 ok(jQuery.browser.opera, "error");
1802 ok(jQuery.browser.opera, "error");
1808 equals(false, "error");
1809 // Do this because opera simply refuses to implement 304 handling :(
1810 // A feature-driven way of detecting this would be appreciated
1811 // See: http://gist.github.com/599419
1812 ok(jQuery.browser.opera, "error");
1818 test("jQuery.ajax - Etag support", function() {
1823 var url = "data/etag.php?ts=" + new Date();
1828 success: function(data, status) {
1829 equals(status, "success");
1834 success: function(data, status) {
1835 if ( data === "FAIL" ) {
1836 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1837 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1839 equals(status, "notmodified");
1840 ok(data == null, "response body should be empty");
1845 // Do this because opera simply refuses to implement 304 handling :(
1846 // A feature-driven way of detecting this would be appreciated
1847 // See: http://gist.github.com/599419
1848 ok(jQuery.browser.opera, "error");
1849 ok(jQuery.browser.opera, "error");
1855 // Do this because opera simply refuses to implement 304 handling :(
1856 // A feature-driven way of detecting this would be appreciated
1857 // See: http://gist.github.com/599419
1858 ok(jQuery.browser.opera, "error");
1864 test("jQuery ajax - failing cross-domain", function() {
1873 url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
1874 success: function(){ ok( false , "success" ); },
1875 error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
1876 complete: function() { if ( ! --i ) start(); }
1880 url: 'http://www.google.com',
1881 success: function(){ ok( false , "success" ); },
1882 error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
1883 complete: function() { if ( ! --i ) start(); }
1888 test("jQuery ajax - atom+xml", function() {
1893 url: url( 'data/atom+xml.php' ),
1894 success: function(){ ok( true , "success" ); },
1895 error: function(){ ok( false , "error" ); },
1896 complete: function() { start(); }
1901 test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
1902 var success = false;
1904 var xhr = jQuery.ajax({ url: window.location });
1909 ok( success, "document.location did not generate exception" );
1912 test( "jQuery.ajax - statusCode" , function() {
1919 function countComplete() {
1925 function createStatusCodes( name , isSuccess ) {
1926 name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
1929 ok( isSuccess , name );
1932 ok( ! isSuccess , name );
1938 "data/name.html": true,
1939 "data/someFileThatDoesNotExist.html": false
1940 } , function( uri , isSuccess ) {
1942 jQuery.ajax( url( uri ) , {
1943 statusCode: createStatusCodes( "in options" , isSuccess ),
1944 complete: countComplete
1947 jQuery.ajax( url( uri ) , {
1948 complete: countComplete
1949 }).statusCode( createStatusCodes( "immediately with method" , isSuccess ) );
1951 jQuery.ajax( url( uri ) , {
1952 complete: function(jXHR) {
1953 jXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) );
1958 jQuery.ajax( url( uri ) , {
1959 complete: function(jXHR) {
1960 setTimeout( function() {
1961 jXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) );
1967 jQuery.ajax( url( uri ) , {
1968 statusCode: createStatusCodes( "all (options)" , isSuccess ),
1969 complete: function(jXHR) {
1970 jXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) );
1971 setTimeout( function() {
1972 jXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) );
1976 }).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) );
1978 var testString = "";
1980 jQuery.ajax( url( uri ), {
1981 success: function( a , b , jXHR ) {
1982 ok( isSuccess , "success" );
1983 var statusCode = {};
1984 statusCode[ jXHR.status ] = function() {
1987 jXHR.statusCode( statusCode );
1990 error: function( jXHR ) {
1991 ok( ! isSuccess , "error" );
1992 var statusCode = {};
1993 statusCode[ jXHR.status ] = function() {
1996 jXHR.statusCode( statusCode );
1999 complete: function() {
2000 strictEqual( testString , "AB" , "Test statusCode callbacks are ordered like " +
2001 ( isSuccess ? "success" : "error" ) + " callbacks" );
2009 test("jQuery.ajax - transitive conversions", function() {
2017 jQuery.ajax( url("data/json.php") , {
2019 "json myjson": function( data ) {
2020 ok( true , "converter called" );
2025 success: function() {
2026 ok( true , "Transitive conversion worked" );
2027 strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" );
2028 strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType" );
2032 jQuery.ajax( url("data/json.php") , {
2034 "json myjson": function( data ) {
2035 ok( true , "converter called (*)" );
2039 contents: false, /* headers are wrong so we ignore them */
2040 dataType: "* myjson",
2041 success: function() {
2042 ok( true , "Transitive conversion worked (*)" );
2043 strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" );
2044 strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType (*)" );
2048 ).then( start , start );
2052 test("jQuery.ajax - active counter", function() {
2053 ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );