1 QUnit
.module( "ajax", {
2 afterEach: function() {
3 jQuery( document
).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
4 moduleTeardown
.apply( this, arguments
);
9 QUnit
.test( "Unit Testing Environment", function( assert
) {
12 assert
.ok( hasPHP
, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" );
13 assert
.ok( !isLocal
, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" );
16 if ( !jQuery
.ajax
|| ( isLocal
&& !hasPHP
) ) {
20 function addGlobalEvents( expected
, assert
) {
22 expected
= expected
|| "";
23 jQuery( document
).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e
) {
24 assert
.ok( expected
.indexOf( e
.type
) !== -1, e
.type
);
29 //----------- jQuery.ajax()
32 "XMLHttpRequest - Attempt to block tests because of dangling XHR requests (IE)",
33 "ajax/unreleasedXHR.html",
36 assert
.ok( true, "done" );
40 ajaxTest( "jQuery.ajax() - success callbacks", 8, function( assert
) {
42 setup
: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert
),
43 url
: url( "name.html" ),
44 beforeSend: function() {
45 assert
.ok( true, "beforeSend" );
48 assert
.ok( true, "success" );
50 complete: function() {
51 assert
.ok( true, "complete" );
56 ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, function( assert
) {
58 setup
: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert
),
59 create: function( options
) {
60 return jQuery
.ajax( url( "name.html" ), options
);
62 beforeSend: function() {
63 assert
.ok( true, "beforeSend" );
66 assert
.ok( true, "success" );
68 complete: function() {
69 assert
.ok( true, "complete" );
74 ajaxTest( "jQuery.ajax() - execute js for crossOrigin when dataType option is provided", 3,
77 create: function( options
) {
78 options
.crossDomain
= true;
79 options
.dataType
= "script";
80 return jQuery
.ajax( url( "mock.php?action=script&header=ecma" ), options
);
83 assert
.ok( true, "success" );
85 complete: function() {
86 assert
.ok( true, "complete" );
92 ajaxTest( "jQuery.ajax() - custom attributes for script tag", 4,
95 create: function( options
) {
97 options
.dataType
= "script";
98 options
.scriptAttrs
= { id
: "jquery-ajax-test", async
: "async" };
99 xhr
= jQuery
.ajax( url( "mock.php?action=script" ), options
);
100 assert
.equal( jQuery( "#jquery-ajax-test" ).attr( "async" ), "async", "attr value" );
103 success: function() {
104 assert
.ok( true, "success" );
106 complete: function() {
107 assert
.ok( true, "complete" );
113 ajaxTest( "jQuery.ajax() - do not execute js (crossOrigin)", 2, function( assert
) {
115 create: function( options
) {
116 options
.crossDomain
= true;
117 return jQuery
.ajax( url( "mock.php?action=script" ), options
);
119 success: function() {
120 assert
.ok( true, "success" );
123 if ( jQuery
.support
.cors
=== false ) {
124 assert
.ok( true, "fail" );
127 complete: function() {
128 assert
.ok( true, "complete" );
133 ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, function( assert
) {
135 setup
: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert
),
136 url
: url( "name.html" ),
137 beforeSend: function() {
138 assert
.ok( true, "beforeSend" );
141 afterSend: function( request
) {
142 request
.always( function() {
143 assert
.ok( true, "complete" );
144 } ).done( function() {
145 assert
.ok( true, "success" );
146 } ).fail( function() {
147 assert
.ok( false, "error" );
153 ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, function( assert
) {
155 setup
: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert
),
156 url
: url( "name.html" ),
157 beforeSend: function() {
158 assert
.ok( true, "beforeSend" );
161 complete: function( xhr
) {
162 xhr
.always( function() {
163 assert
.ok( true, "complete" );
164 } ).done( function() {
165 assert
.ok( true, "success" );
166 } ).fail( function() {
167 assert
.ok( false, "error" );
173 ajaxTest( "jQuery.ajax() - error callbacks", 8, function( assert
) {
175 setup
: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert
),
176 url
: url( "mock.php?action=wait&wait=5" ),
177 beforeSend: function() {
178 assert
.ok( true, "beforeSend" );
180 afterSend: function( request
) {
184 assert
.ok( true, "error" );
186 complete: function() {
187 assert
.ok( true, "complete" );
192 ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, function( assert
) {
194 url
: url( "mock.php?action=wait&wait=5" ),
195 error: function( _
, textStatus
, errorThrown
) {
196 assert
.strictEqual( textStatus
, "abort", "textStatus is 'abort' for abort" );
197 assert
.strictEqual( errorThrown
, "abort", "errorThrown is 'abort' for abort" );
199 afterSend: function( request
) {
204 url
: url( "mock.php?action=wait&wait=5" ),
205 error: function( _
, textStatus
, errorThrown
) {
206 assert
.strictEqual( textStatus
, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
207 assert
.strictEqual( errorThrown
, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" );
209 afterSend: function( request
) {
210 request
.abort( "mystatus" );
215 ajaxTest( "jQuery.ajax() - responseText on error", 1, function( assert
) {
217 url
: url( "mock.php?action=error" ),
218 error: function( xhr
) {
219 assert
.strictEqual( xhr
.responseText
, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" );
224 QUnit
.test( "jQuery.ajax() - retry with jQuery.ajax( this )", function( assert
) {
228 done
= assert
.async();
230 url
: url( "mock.php?action=error" ),
236 assert
.ok( true, "Test retrying with jQuery.ajax(this) works" );
238 url
: url( "mock.php?action=error&x=2" ),
239 beforeSend: function() {
240 if ( !previousUrl
) {
241 previousUrl
= this.url
;
243 assert
.strictEqual( this.url
, previousUrl
, "url parameters are not re-appended" );
257 ajaxTest( "jQuery.ajax() - headers", 8, function( assert
) {
260 jQuery( document
).ajaxSend( function( evt
, xhr
) {
261 xhr
.setRequestHeader( "ajax-send", "test" );
264 url
: url( "mock.php?action=headers&keys=siMPle|SometHing-elsE|OthEr|Nullable|undefined|Empty|ajax-send" ),
267 "SometHing-elsE": "other value",
268 "OthEr": "something else",
270 "undefined": undefined
272 // Support: IE 9 - 11, Edge 12 - 14 only
273 // Not all browsers allow empty-string headers
276 success: function( data
, _
, xhr
) {
278 isAndroid
= /android 4\.[0-3]/i.test( navigator
.userAgent
),
279 requestHeaders
= jQuery
.extend( this.headers
, {
283 for ( i
in requestHeaders
) {
284 tmp
.push( i
, ": ", requestHeaders
[ i
] + "", "\n" );
286 tmp
= tmp
.join( "" );
288 assert
.strictEqual( data
, tmp
, "Headers were sent" );
289 assert
.strictEqual( xhr
.getResponseHeader( "Sample-Header" ), "Hello World", "Sample header received" );
290 assert
.ok( data
.indexOf( "undefined" ) < 0, "Undefined header value was not sent" );
292 emptyHeader
= xhr
.getResponseHeader( "Empty-Header" );
293 if ( emptyHeader
=== null ) {
294 assert
.ok( true, "Firefox doesn't support empty headers" );
296 assert
.strictEqual( emptyHeader
, "", "Empty header received" );
298 assert
.strictEqual( xhr
.getResponseHeader( "Sample-Header2" ), "Hello World 2", "Second sample header received" );
301 // Support: Android 4.0-4.3 only
302 // Android Browser only returns the last value for each header
303 // so there's no way for jQuery get all parts.
304 assert
.ok( true, "Android doesn't support repeated header names" );
306 assert
.strictEqual( xhr
.getResponseHeader( "List-Header" ), "Item 1, Item 2", "List header received" );
309 if ( isAndroid
&& QUnit
.isSwarm
) {
310 // Support: Android 4.0-4.3 on BrowserStack only
311 // Android Browser versions provided by BrowserStack fail this test
312 // while locally fired emulators don't, even when they connect
313 // to TestSwarm. Just skip the test there to avoid a red build.
314 assert
.ok( true, "BrowserStack's Android fails the \"prototype collision (constructor)\" test" );
316 assert
.strictEqual( xhr
.getResponseHeader( "constructor" ), "prototype collision (constructor)", "constructor header received" );
318 assert
.strictEqual( xhr
.getResponseHeader( "__proto__" ), null, "Undefined __proto__ header not received" );
323 ajaxTest( "jQuery.ajax() - Accept header", 1, function( assert
) {
325 url
: url( "mock.php?action=headers&keys=accept" ),
327 Accept
: "very wrong accept value"
329 beforeSend: function( xhr
) {
330 xhr
.setRequestHeader( "Accept", "*/*" );
332 success: function( data
) {
333 assert
.strictEqual( data
, "accept: */*\n", "Test Accept header is set to last value provided" );
338 ajaxTest( "jQuery.ajax() - contentType", 2, function( assert
) {
341 url
: url( "mock.php?action=headers&keys=content-type" ),
343 success: function( data
) {
344 assert
.strictEqual( data
, "content-type: test\n", "Test content-type is sent when options.contentType is set" );
348 url
: url( "mock.php?action=headers&keys=content-type" ),
350 success: function( data
) {
352 // Some server/interpreter combinations always supply a Content-Type to scripts
353 data
= data
|| "content-type: \n";
354 assert
.strictEqual( data
, "content-type: \n", "Test content-type is not set when options.contentType===false" );
360 ajaxTest( "jQuery.ajax() - protocol-less urls", 1, function( assert
) {
362 url
: "//somedomain.com",
363 beforeSend: function( xhr
, settings
) {
364 assert
.equal( settings
.url
, location
.protocol
+ "//somedomain.com", "Make sure that the protocol is added." );
371 ajaxTest( "jQuery.ajax() - URL fragment component preservation", 4, function( assert
) {
374 url
: baseURL
+ "name.html#foo",
375 beforeSend: function( xhr
, settings
) {
376 assert
.equal( settings
.url
, baseURL
+ "name.html#foo",
377 "hash preserved for request with no query component." );
383 url
: baseURL
+ "name.html?abc#foo",
384 beforeSend: function( xhr
, settings
) {
385 assert
.equal( settings
.url
, baseURL
+ "name.html?abc#foo",
386 "hash preserved for request with query component." );
392 url
: baseURL
+ "name.html?abc#foo",
396 beforeSend: function( xhr
, settings
) {
397 assert
.equal( settings
.url
, baseURL
+ "name.html?abc&test=123#foo",
398 "hash preserved for request with query component and data." );
404 url
: baseURL
+ "name.html?abc#brownies",
409 beforeSend: function( xhr
, settings
) {
410 // Clear the cache-buster param value
411 var url
= settings
.url
.replace( /_=[^&#]+/, "_=" );
412 assert
.equal( url
, baseURL
+ "name.html?abc&devo=hat&_=#brownies",
413 "hash preserved for cache-busting request with query component and data." );
421 ajaxTest( "jQuery.ajax() - traditional param encoding", 4, function( assert
) {
431 beforeSend: function( xhr
, settings
) {
432 assert
.equal( settings
.url
, "/?devo=hat&answer=42&quux=a%20space", "Simple case" );
442 "b[]": [ "b1", "b2" ]
444 beforeSend: function( xhr
, settings
) {
445 assert
.equal( settings
.url
, "/?a=1&a=2&a=3&b%5B%5D=b1&b%5B%5D=b2", "Arrays" );
454 "a": [ [ 1, 2 ], [ 3, 4 ], 5 ]
456 beforeSend: function( xhr
, settings
) {
457 assert
.equal( settings
.url
, "/?a=1%2C2&a=3%2C4&a=5", "Nested arrays" );
466 "a": [ "w", [ [ "x", "y" ], "z" ] ]
469 beforeSend: function( xhr
, settings
) {
470 var url
= settings
.url
.replace( /\d{3,}/, "" );
471 assert
.equal( url
, "/?a=w&a=x%2Cy%2Cz&_=", "Cache-buster" );
479 ajaxTest( "jQuery.ajax() - cross-domain detection", 8, function( assert
) {
480 function request( url
, title
, crossDomainOrOptions
) {
481 return jQuery
.extend( {
484 beforeSend: function( _
, s
) {
485 assert
.ok( crossDomainOrOptions
=== false ? !s
.crossDomain
: s
.crossDomain
, title
);
489 }, crossDomainOrOptions
);
492 var loc
= document
.location
,
493 samePort
= loc
.port
|| ( loc
.protocol
=== "http:" ? 80 : 443 ),
494 otherPort
= loc
.port
=== 666 ? 667 : 666,
495 otherProtocol
= loc
.protocol
=== "http:" ? "https:" : "http:";
499 loc
.protocol
+ "//" + loc
.hostname
+ ":" + samePort
,
500 "Test matching ports are not detected as cross-domain",
504 otherProtocol
+ "//" + loc
.host
,
505 "Test different protocols are detected as cross-domain"
509 "Adobe AIR app:/ URL detected as cross-domain"
512 loc
.protocol
+ "//example.invalid:" + ( loc
.port
|| 80 ),
513 "Test different hostnames are detected as cross-domain"
516 loc
.protocol
+ "//" + loc
.hostname
+ ":" + otherPort
,
517 "Test different ports are detected as cross-domain"
521 "Test about:blank is detected as cross-domain"
524 loc
.protocol
+ "//" + loc
.host
,
525 "Test forced crossDomain is detected as cross-domain",
531 " http://otherdomain.com",
532 "Cross-domain url with leading space is detected as cross-domain"
537 ajaxTest( "jQuery.ajax() - abort", 9, function( assert
) {
539 setup
: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete", assert
),
540 url
: url( "mock.php?action=wait&wait=5" ),
541 beforeSend: function() {
542 assert
.ok( true, "beforeSend" );
544 afterSend: function( xhr
) {
545 assert
.strictEqual( xhr
.readyState
, 1, "XHR readyState indicates successful dispatch" );
547 assert
.strictEqual( xhr
.readyState
, 0, "XHR readyState indicates successful abortion" );
550 complete: function() {
551 assert
.ok( true, "complete" );
556 if ( !/android 4\.0/i.test( navigator
.userAgent
) ) {
557 ajaxTest( "jQuery.ajax() - native abort", 2, function( assert
) {
559 url
: url( "mock.php?action=wait&wait=1" ),
561 var xhr
= new window
.XMLHttpRequest();
562 setTimeout( function() {
567 error: function( xhr
, msg
) {
568 assert
.strictEqual( msg
, "error", "Native abort triggers error callback" );
570 complete: function() {
571 assert
.ok( true, "complete" );
577 // Support: Android <= 4.0 - 4.3 only
578 // Android 4.0-4.3 does not have ontimeout on an xhr
579 if ( "ontimeout" in new window
.XMLHttpRequest() ) {
580 ajaxTest( "jQuery.ajax() - native timeout", 2, function( assert
) {
582 url
: url( "mock.php?action=wait&wait=1" ),
584 var xhr
= new window
.XMLHttpRequest();
588 error: function( xhr
, msg
) {
589 assert
.strictEqual( msg
, "error", "Native timeout triggers error callback" );
591 complete: function() {
592 assert
.ok( true, "complete" );
598 ajaxTest( "jQuery.ajax() - events with context", 12, function( assert
) {
599 var context
= document
.createElement( "div" );
601 function event( e
) {
602 assert
.equal( this, context
, e
.type
);
605 function callback( msg
) {
607 assert
.equal( this, context
, "context is preserved on callback " + msg
);
613 jQuery( context
).appendTo( "#foo" )
615 .ajaxComplete( event
)
617 .ajaxSuccess( event
);
620 url
: url( "name.html" ),
622 beforeSend
: callback( "beforeSend" ),
623 success
: callback( "success" ),
624 complete
: callback( "complete" )
626 url
: url( "404.txt" ),
628 beforeSend
: callback( "beforeSend" ),
629 error
: callback( "error" ),
630 complete
: callback( "complete" )
635 ajaxTest( "jQuery.ajax() - events without context", 3, function( assert
) {
636 function nocallback( msg
) {
638 assert
.equal( typeof this.url
, "string", "context is settings on callback " + msg
);
642 url
: url( "404.txt" ),
643 beforeSend
: nocallback( "beforeSend" ),
644 error
: nocallback( "error" ),
645 complete
: nocallback( "complete" )
649 ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function( assert
) {
652 url
: url( "mock.php?action=json" ),
654 holder
= jQuery
.event
;
657 complete: function() {
658 assert
.ok( true, "Call can be made without jQuery.event" );
659 jQuery
.event
= holder
;
665 ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, function( assert
) {
668 jQuery( document
).on( "ajaxSend", function( e
, jqXHR
) {
672 jQuery( document
).on( "ajaxError ajaxComplete", function( e
, jqXHR
) {
673 assert
.equal( jqXHR
.statusText
, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" );
676 url
: url( "name.html" ),
678 complete: function() {
679 assert
.ok( true, "complete" );
684 ajaxTest( "jQuery.ajax() - context modification", 1, function( assert
) {
686 url
: url( "name.html" ),
688 beforeSend: function() {
691 afterSend: function() {
692 assert
.strictEqual( this.context
.test
, "foo", "Make sure the original object is maintained." );
698 ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function( assert
) {
705 assert
.strictEqual( jQuery
.ajaxSettings
.context
, obj
, "Make sure the context is properly set in ajaxSettings." );
708 url
: url( "name.html" ),
709 success: function() {
710 assert
.strictEqual( this, obj
, "Make sure the original object is maintained." );
713 url
: url( "name.html" ),
715 success: function() {
716 assert
.ok( this !== obj
, "Make sure overriding context is possible." );
722 ajaxTest( "jQuery.ajax() - disabled globals", 3, function( assert
) {
724 setup
: addGlobalEvents( "", assert
),
726 url
: url( "name.html" ),
727 beforeSend: function() {
728 assert
.ok( true, "beforeSend" );
730 success: function() {
731 assert
.ok( true, "success" );
733 complete: function() {
734 assert
.ok( true, "complete" );
739 ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, function( assert
) {
741 url
: url( "with_fries.xml" ),
743 success: function( resp
) {
744 assert
.equal( jQuery( "properties", resp
).length
, 1, "properties in responseXML" );
745 assert
.equal( jQuery( "jsconf", resp
).length
, 1, "jsconf in responseXML" );
746 assert
.equal( jQuery( "thing", resp
).length
, 2, "things in responseXML" );
751 ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, function( assert
) {
753 url
: url( "mock.php?action=xmlOverJsonp" ),
754 dataType
: "jsonp xml",
755 success: function( resp
) {
756 assert
.equal( jQuery( "properties", resp
).length
, 1, "properties in responseXML" );
757 assert
.equal( jQuery( "jsconf", resp
).length
, 1, "jsconf in responseXML" );
758 assert
.equal( jQuery( "thing", resp
).length
, 2, "things in responseXML" );
763 ajaxTest( "jQuery.ajax() - HEAD requests", 2, function( assert
) {
766 url
: url( "name.html" ),
768 success: function( data
, status
, xhr
) {
769 assert
.ok( /Date/i.test( xhr
.getAllResponseHeaders() ), "No Date in HEAD response" );
773 url
: url( "name.html" ),
778 success: function( data
, status
, xhr
) {
779 assert
.ok( /Date/i.test( xhr
.getAllResponseHeaders() ), "No Date in HEAD response with data" );
785 ajaxTest( "jQuery.ajax() - beforeSend", 1, function( assert
) {
787 url
: url( "name.html" ),
788 beforeSend: function() {
791 success: function() {
792 assert
.ok( this.check
, "check beforeSend was executed" );
797 ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, function( assert
) {
800 return jQuery
.ajax( {
801 url
: url( "name.html" ),
802 beforeSend: function( xhr
) {
803 assert
.ok( true, "beforeSend got called, canceling" );
806 success: function() {
807 assert
.ok( false, "request didn't get canceled" );
809 complete: function() {
810 assert
.ok( false, "request didn't get canceled" );
813 assert
.ok( false, "request didn't get canceled" );
817 fail: function( _
, reason
) {
818 assert
.strictEqual( reason
, "canceled", "canceled request must fail with 'canceled' status text" );
823 ajaxTest( "jQuery.ajax() - dataType html", 5, function( assert
) {
826 Globals
.register( "testFoo" );
827 Globals
.register( "testBar" );
830 url
: url( "mock.php?action=testHTML&baseURL=" + baseURL
),
831 success: function( data
) {
832 assert
.ok( data
.match( /^html text/ ), "Check content for datatype html" );
833 jQuery( "#ap" ).html( data
);
834 assert
.strictEqual( window
[ "testFoo" ], "foo", "Check if script was evaluated for datatype html" );
835 assert
.strictEqual( window
[ "testBar" ], "bar", "Check if script src was evaluated for datatype html" );
840 ajaxTest( "jQuery.ajax() - synchronous request", 1, function( assert
) {
842 url
: url( "json_obj.js" ),
846 afterSend: function( xhr
) {
847 assert
.ok( /^\{ "data"/.test( xhr
.responseText
), "check returned text" );
852 ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, function( assert
) {
854 url
: url( "json_obj.js" ),
858 afterSend: function( xhr
) {
860 xhr
.done( function( data
) {
861 assert
.ok( true, "success callback executed" );
864 assert
.ok( /^\{ "data"/.test( result
), "check returned text" );
869 QUnit
.test( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", function( assert
) {
871 var done
= assert
.async();
872 var target
= "name.html",
876 success = function() {
879 jQuery( document
).on( "ajaxError.passthru", function( e
, xml
) {
881 errorEx
+= ": " + xml
.status
;
883 jQuery( document
).one( "ajaxStop", function() {
884 assert
.equal( successCount
, 5, "Check all ajax calls successful" );
885 assert
.equal( errorCount
, 0, "Check no ajax errors (status" + errorEx
+ ")" );
886 jQuery( document
).off( "ajaxError.passthru" );
889 Globals
.register( "testBar" );
891 assert
.ok( jQuery
.get( url( target
), success
), "get" );
892 assert
.ok( jQuery
.post( url( target
), success
), "post" );
893 assert
.ok( jQuery
.getScript( url( "mock.php?action=testbar" ), success
), "script" );
894 assert
.ok( jQuery
.getJSON( url( "json_obj.js" ), success
), "json" );
895 assert
.ok( jQuery
.ajax( {
901 ajaxTest( "jQuery.ajax() - cache", 28, function( assert
) {
902 var re
= /_=(.*?)(&|$)/g,
903 rootUrl
= baseURL
+ "text.txt";
905 function request( url
, title
) {
909 beforeSend: function() {
913 assert
.equal( this.url
.indexOf( rootUrl
), 0, "root url not mangled: " + this.url
);
914 assert
.equal( /\&.*\?/.test( this.url
), false, "parameter delimiters in order" );
916 while ( ( tmp
= re
.exec( this.url
) ) ) {
917 assert
.strictEqual( parameter
, undefined, title
+ ": only one 'no-cache' parameter" );
918 parameter
= tmp
[ 1 ];
919 assert
.notStrictEqual( parameter
, "tobereplaced555", title
+ ": parameter (if it was there) was replaced" );
937 rootUrl
+ "?pizza=true",
941 rootUrl
+ "?_=tobereplaced555",
945 rootUrl
+ "?pizza=true&_=tobereplaced555",
949 rootUrl
+ "?_=tobereplaced555&tv=false",
953 rootUrl
+ "?name=David&_=tobereplaced555&washere=true",
954 "2 parameters surrounding _="
959 jQuery
.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain
, label
) {
961 ajaxTest( "jQuery.ajax() - JSONP - Query String (?n)" + label
, 4, function( assert
) {
964 url
: baseURL
+ "mock.php?action=jsonp&callback=?",
966 crossDomain
: crossDomain
,
967 success: function( data
) {
968 assert
.ok( data
.data
, "JSON results returned (GET, url callback)" );
972 url
: baseURL
+ "mock.php?action=jsonp&callback=??",
974 crossDomain
: crossDomain
,
975 success: function( data
) {
976 assert
.ok( data
.data
, "JSON results returned (GET, url context-free callback)" );
980 url
: baseURL
+ "mock.php/???action=jsonp",
982 crossDomain
: crossDomain
,
983 success: function( data
) {
984 assert
.ok( data
.data
, "JSON results returned (GET, REST-like)" );
988 url
: baseURL
+ "mock.php/???action=jsonp&array=1",
990 crossDomain
: crossDomain
,
991 success: function( data
) {
992 assert
.ok( Array
.isArray( data
), "JSON results returned (GET, REST-like with param)" );
998 ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label
, 10, function( assert
) {
1001 Globals
.register( "functionToCleanUp" );
1002 Globals
.register( "XXX" );
1003 Globals
.register( "jsonpResults" );
1004 window
[ "jsonpResults" ] = function( data
) {
1005 assert
.ok( data
[ "data" ], "JSON results returned (GET, custom callback function)" );
1009 url
: baseURL
+ "mock.php?action=jsonp",
1011 crossDomain
: crossDomain
,
1013 success: function( data
) {
1014 assert
.ok( data
[ "data" ], "JSON results returned (GET, data obj callback)" );
1017 url
: baseURL
+ "mock.php?action=jsonp",
1019 crossDomain
: crossDomain
,
1020 jsonpCallback
: "jsonpResults",
1021 success: function( data
) {
1023 typeof window
[ "jsonpResults" ],
1025 "should not rewrite original function"
1027 assert
.ok( data
.data
, "JSON results returned (GET, custom callback name)" );
1030 url
: baseURL
+ "mock.php?action=jsonp",
1032 crossDomain
: crossDomain
,
1033 jsonpCallback
: "functionToCleanUp",
1034 success: function( data
) {
1035 assert
.ok( data
[ "data" ], "JSON results returned (GET, custom callback name to be cleaned up)" );
1036 assert
.strictEqual( window
[ "functionToCleanUp" ], true, "Callback was removed (GET, custom callback name to be cleaned up)" );
1039 url
: baseURL
+ "mock.php?action=jsonp",
1041 crossDomain
: crossDomain
,
1042 jsonpCallback
: "functionToCleanUp",
1043 beforeSend: function( jqXHR
) {
1048 xhr
.fail( function() {
1049 assert
.ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
1050 assert
.strictEqual( window
[ "functionToCleanUp" ], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
1054 url
: baseURL
+ "mock.php?action=jsonp&callback=XXX",
1057 jsonpCallback
: "XXX",
1058 crossDomain
: crossDomain
,
1059 beforeSend: function() {
1060 assert
.ok( /action=jsonp&callback=XXX&_=\d+$/.test( this.url
), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
1062 success: function( data
) {
1063 assert
.ok( data
[ "data" ], "JSON results returned (GET, custom callback name with no url manipulation)" );
1069 ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label
, 2, function( assert
) {
1072 url
: baseURL
+ "mock.php?action=jsonp",
1074 crossDomain
: crossDomain
,
1076 success: function( data
) {
1077 assert
.ok( data
.data
, "JSON results returned (GET, data callback)" );
1081 url
: baseURL
+ "mock.php?action=jsonp",
1083 crossDomain
: crossDomain
,
1084 data
: "callback=??",
1085 success: function( data
) {
1086 assert
.ok( data
.data
, "JSON results returned (GET, data context-free callback)" );
1092 ajaxTest( "jQuery.ajax() - JSONP - POST" + label
, 3, function( assert
) {
1096 url
: baseURL
+ "mock.php?action=jsonp",
1098 crossDomain
: crossDomain
,
1099 success: function( data
) {
1100 assert
.ok( data
[ "data" ], "JSON results returned (POST, no callback)" );
1105 url
: baseURL
+ "mock.php?action=jsonp",
1108 crossDomain
: crossDomain
,
1109 success: function( data
) {
1110 assert
.ok( data
[ "data" ], "JSON results returned (POST, data callback)" );
1115 url
: baseURL
+ "mock.php?action=jsonp",
1118 crossDomain
: crossDomain
,
1119 success: function( data
) {
1120 assert
.ok( data
[ "data" ], "JSON results returned (POST, data obj callback)" );
1126 ajaxTest( "jQuery.ajax() - JSONP" + label
, 3, function( assert
) {
1129 url
: baseURL
+ "mock.php?action=jsonp",
1131 crossDomain
: crossDomain
,
1132 success: function( data
) {
1133 assert
.ok( data
.data
, "JSON results returned (GET, no callback)" );
1137 create: function( options
) {
1138 var request
= jQuery
.ajax( options
),
1139 promise
= request
.then( function( data
) {
1140 assert
.ok( data
.data
, "first request: JSON results returned (GET, no callback)" );
1141 request
= jQuery
.ajax( this ).done( function( data
) {
1142 assert
.ok( data
.data
, "this re-used: JSON results returned (GET, no callback)" );
1144 promise
.abort
= request
.abort
;
1147 promise
.abort
= request
.abort
;
1150 url
: baseURL
+ "mock.php?action=jsonp",
1152 crossDomain
: crossDomain
,
1160 ajaxTest( "jQuery.ajax() - script, Remote", 2, function( assert
) {
1163 Globals
.register( "testBar" );
1165 url
: url( "mock.php?action=testbar" ),
1167 success: function() {
1168 assert
.strictEqual( window
[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
1173 ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, function( assert
) {
1176 Globals
.register( "testBar" );
1178 url
: url( "mock.php?action=testbar" ),
1181 success: function( data
, status
) {
1182 assert
.strictEqual( window
[ "testBar" ], "bar", "Script results returned (POST, no callback)" );
1183 assert
.strictEqual( status
, "success", "Script results returned (POST, no callback)" );
1188 ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, function( assert
) {
1191 Globals
.register( "testBar" );
1193 url
: url( "mock.php?action=testbar" ),
1195 success: function() {
1196 assert
.strictEqual( window
[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
1201 ajaxTest( "jQuery.ajax() - malformed JSON", 2, function( assert
) {
1203 url
: baseURL
+ "badjson.js",
1205 error: function( xhr
, msg
, detailedMsg
) {
1206 assert
.strictEqual( msg
, "parsererror", "A parse error occurred." );
1207 assert
.ok( /(invalid|error|exception)/i.test( detailedMsg
), "Detailed parsererror message provided" );
1212 ajaxTest( "jQuery.ajax() - script by content-type", 2, function() {
1215 url
: baseURL
+ "mock.php?action=script",
1222 url
: baseURL
+ "mock.php?action=script",
1231 ajaxTest( "jQuery.ajax() - JSON by content-type", 5, function( assert
) {
1233 url
: baseURL
+ "mock.php?action=json",
1238 success: function( json
) {
1239 assert
.ok( json
.length
>= 2, "Check length" );
1240 assert
.strictEqual( json
[ 0 ][ "name" ], "John", "Check JSON: first, name" );
1241 assert
.strictEqual( json
[ 0 ][ "age" ], 21, "Check JSON: first, age" );
1242 assert
.strictEqual( json
[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
1243 assert
.strictEqual( json
[ 1 ][ "age" ], 25, "Check JSON: second, age" );
1248 ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, function( assert
) {
1250 url
: url( "mock.php?action=json" ),
1258 success: function( text
) {
1259 assert
.strictEqual( typeof text
, "string", "json wasn't auto-determined" );
1260 var json
= JSON
.parse( text
);
1261 assert
.ok( json
.length
>= 2, "Check length" );
1262 assert
.strictEqual( json
[ 0 ][ "name" ], "John", "Check JSON: first, name" );
1263 assert
.strictEqual( json
[ 0 ][ "age" ], 21, "Check JSON: first, age" );
1264 assert
.strictEqual( json
[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
1265 assert
.strictEqual( json
[ 1 ][ "age" ], 25, "Check JSON: second, age" );
1270 ajaxTest( "jQuery.ajax() - simple get", 1, function( assert
) {
1273 url
: url( "mock.php?action=name&name=foo" ),
1274 success: function( msg
) {
1275 assert
.strictEqual( msg
, "bar", "Check for GET" );
1280 ajaxTest( "jQuery.ajax() - simple post", 1, function( assert
) {
1283 url
: url( "mock.php?action=name" ),
1285 success: function( msg
) {
1286 assert
.strictEqual( msg
, "pan", "Check for POST" );
1291 ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, function( assert
) {
1293 url
: baseURL
+ "mock.php?action=echoData",
1296 success: function( result
) {
1297 assert
.strictEqual( result
, "" );
1302 ajaxTest( "jQuery.ajax() - data - x-www-form-urlencoded (gh-2658)", 1, function( assert
) {
1305 data
: { devo
: "A Beautiful World" },
1307 beforeSend: function( _
, s
) {
1308 assert
.strictEqual( s
.data
, "devo=A+Beautiful+World", "data is '+'-encoded" );
1315 ajaxTest( "jQuery.ajax() - data - text/plain (gh-2658)", 1, function( assert
) {
1318 data
: { devo
: "A Beautiful World" },
1320 contentType
: "text/plain",
1321 beforeSend: function( _
, s
) {
1322 assert
.strictEqual( s
.data
, "devo=A%20Beautiful%20World", "data is %20-encoded" );
1329 ajaxTest( "jQuery.ajax() - data - no processing POST", 1, function( assert
) {
1332 data
: { devo
: "A Beautiful World" },
1334 contentType
: "x-special-sauce",
1336 beforeSend: function( _
, s
) {
1337 assert
.deepEqual( s
.data
, { devo
: "A Beautiful World" }, "data is not processed" );
1344 ajaxTest( "jQuery.ajax() - data - no processing GET", 1, function( assert
) {
1347 data
: { devo
: "A Beautiful World" },
1349 contentType
: "x-something-else",
1351 beforeSend: function( _
, s
) {
1352 assert
.deepEqual( s
.data
, { devo
: "A Beautiful World" }, "data is not processed" );
1359 ajaxTest( "jQuery.ajax() - data - process string with GET", 2, function( assert
) {
1364 contentType
: "x-something-else",
1366 beforeSend: function( _
, s
) {
1367 assert
.equal( s
.url
, "bogus.html?a=1&b=2", "added data to url" );
1368 assert
.equal( s
.data
, undefined, "removed data from settings" );
1375 var ifModifiedNow
= new Date();
1378 /* jQuery.each arguments start */
1381 " (no cache)": false
1383 function( label
, cache
) {
1386 "If-Modified-Since": "mock.php?action=ims",
1387 "Etag": "mock.php?action=etag"
1389 function( type
, url
) {
1390 url
= baseURL
+ url
+ "&ts=" + ifModifiedNow
++;
1391 QUnit
.test( "jQuery.ajax() - " + type
+ " support" + label
, function( assert
) {
1393 var done
= assert
.async();
1398 success: function( _
, status
) {
1399 assert
.strictEqual( status
, "success", "Initial status is 'success'" );
1404 success: function( data
, status
, jqXHR
) {
1405 assert
.strictEqual( status
, "notmodified", "Following status is 'notmodified'" );
1406 assert
.strictEqual( jqXHR
.status
, 304, "XHR status is 304" );
1407 assert
.equal( data
, null, "no response body is given" );
1409 complete: function() {
1419 /* jQuery.each arguments end */
1422 ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, function( assert
) {
1426 url
: "http://example.invalid",
1427 error: function( xhr
, _
, e
) {
1428 assert
.ok( true, "file not found: " + xhr
.status
+ " => " + e
);
1433 ajaxTest( "jQuery.ajax() - failing cross-domain", 1, function( assert
) {
1435 url
: "http://" + externalHost
,
1436 error: function( xhr
, _
, e
) {
1437 assert
.ok( true, "access denied: " + xhr
.status
+ " => " + e
);
1442 ajaxTest( "jQuery.ajax() - atom+xml", 1, function( assert
) {
1444 url
: url( "mock.php?action=atom" ),
1445 success: function() {
1446 assert
.ok( true, "success" );
1451 QUnit
.test( "jQuery.ajax() - statusText", function( assert
) {
1453 var done
= assert
.async();
1454 jQuery
.ajax( url( "mock.php?action=status&code=200&text=Hello" ) ).done( function( _
, statusText
, jqXHR
) {
1455 assert
.strictEqual( statusText
, "success", "callback status text ok for success" );
1456 assert
.ok( jqXHR
.statusText
=== "Hello" || jqXHR
.statusText
=== "OK", "jqXHR status text ok for success (" + jqXHR
.statusText
+ ")" );
1457 jQuery
.ajax( url( "mock.php?action=status&code=404&text=World" ) ).fail( function( jqXHR
, statusText
) {
1458 assert
.strictEqual( statusText
, "error", "callback status text ok for error" );
1464 QUnit
.test( "jQuery.ajax() - statusCode", function( assert
) {
1465 assert
.expect( 20 );
1466 var done
= assert
.async(),
1469 function countComplete() {
1475 function createStatusCodes( name
, isSuccess
) {
1476 name
= "Test " + name
+ " " + ( isSuccess
? "success" : "error" );
1479 assert
.ok( isSuccess
, name
);
1482 assert
.ok( !isSuccess
, name
);
1488 /* jQuery.each arguments start */
1493 function( uri
, isSuccess
) {
1494 jQuery
.ajax( url( uri
), {
1495 statusCode
: createStatusCodes( "in options", isSuccess
),
1496 complete
: countComplete
1499 jQuery
.ajax( url( uri
), {
1500 complete
: countComplete
1501 } ).statusCode( createStatusCodes( "immediately with method", isSuccess
) );
1503 jQuery
.ajax( url( uri
), {
1504 complete: function( jqXHR
) {
1505 jqXHR
.statusCode( createStatusCodes( "on complete", isSuccess
) );
1510 jQuery
.ajax( url( uri
), {
1511 complete: function( jqXHR
) {
1512 setTimeout( function() {
1513 jqXHR
.statusCode( createStatusCodes( "very late binding", isSuccess
) );
1519 jQuery
.ajax( url( uri
), {
1520 statusCode
: createStatusCodes( "all (options)", isSuccess
),
1521 complete: function( jqXHR
) {
1522 jqXHR
.statusCode( createStatusCodes( "all (on complete)", isSuccess
) );
1523 setTimeout( function() {
1524 jqXHR
.statusCode( createStatusCodes( "all (very late binding)", isSuccess
) );
1528 } ).statusCode( createStatusCodes( "all (immediately with method)", isSuccess
) );
1530 var testString
= "";
1532 jQuery
.ajax( url( uri
), {
1533 success: function( a
, b
, jqXHR
) {
1534 assert
.ok( isSuccess
, "success" );
1535 var statusCode
= {};
1536 statusCode
[ jqXHR
.status
] = function() {
1539 jqXHR
.statusCode( statusCode
);
1542 error: function( jqXHR
) {
1543 assert
.ok( !isSuccess
, "error" );
1544 var statusCode
= {};
1545 statusCode
[ jqXHR
.status
] = function() {
1548 jqXHR
.statusCode( statusCode
);
1551 complete: function() {
1555 "Test statusCode callbacks are ordered like " + ( isSuccess
? "success" : "error" ) + " callbacks"
1562 /* jQuery.each arguments end*/
1566 ajaxTest( "jQuery.ajax() - transitive conversions", 8, function( assert
) {
1569 url
: url( "mock.php?action=json" ),
1571 "json myJson": function( data
) {
1572 assert
.ok( true, "converter called" );
1577 success: function() {
1578 assert
.ok( true, "Transitive conversion worked" );
1579 assert
.strictEqual( this.dataTypes
[ 0 ], "text", "response was retrieved as text" );
1580 assert
.strictEqual( this.dataTypes
[ 1 ], "myjson", "request expected myjson dataType" );
1584 url
: url( "mock.php?action=json" ),
1586 "json myJson": function( data
) {
1587 assert
.ok( true, "converter called (*)" );
1591 contents
: false, /* headers are wrong so we ignore them */
1592 dataType
: "* myJson",
1593 success: function() {
1594 assert
.ok( true, "Transitive conversion worked (*)" );
1595 assert
.strictEqual( this.dataTypes
[ 0 ], "text", "response was retrieved as text (*)" );
1596 assert
.strictEqual( this.dataTypes
[ 1 ], "myjson", "request expected myjson dataType (*)" );
1602 ajaxTest( "jQuery.ajax() - overrideMimeType", 2, function( assert
) {
1605 url
: url( "mock.php?action=json" ),
1606 beforeSend: function( xhr
) {
1607 xhr
.overrideMimeType( "application/json" );
1609 success: function( json
) {
1610 assert
.ok( json
.data
, "Mimetype overridden using beforeSend" );
1614 url
: url( "mock.php?action=json" ),
1615 mimeType
: "application/json",
1616 success: function( json
) {
1617 assert
.ok( json
.data
, "Mimetype overridden using mimeType option" );
1623 ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, function( assert
) {
1625 url
: url( "mock.php?action=echoData" ),
1626 error: function( _
, __
, error
) {
1627 assert
.equal( typeof error
=== "object", true, "Didn't get back error object for empty json response" );
1633 ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, function( assert
) {
1635 create: function() {
1636 return jQuery
.ajax( {
1637 url
: url( "name.html" ),
1638 beforeSend: function() {
1639 assert
.ok( true, "beforeSend got called, canceling" );
1642 success: function() {
1643 assert
.ok( false, "request didn't get canceled" );
1645 complete: function() {
1646 assert
.ok( false, "request didn't get canceled" );
1649 assert
.ok( false, "request didn't get canceled" );
1653 fail: function( _
, reason
) {
1654 assert
.strictEqual( reason
, "canceled", "canceled request must fail with 'canceled' status text" );
1659 ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, function( assert
) {
1661 url
: baseURL
+ "mock.php?action=echoQuery",
1667 success: function( result
) {
1668 assert
.strictEqual( result
, "action=echoQuery&key=value" );
1673 QUnit
.test( "#7531 - jQuery.ajax() - Location object as url", function( assert
) {
1679 xhr
= jQuery
.ajax( {
1680 url
: window
.location
1687 assert
.ok( success
, "document.location did not generate exception" );
1690 jQuery
.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain
, label
) {
1691 ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label
, 1, function( assert
) {
1693 url
: baseURL
+ "mock.php?action=jsonp",
1695 crossDomain
: crossDomain
,
1696 beforeSend: function() {
1697 assert
.strictEqual( this.cache
, false, "cache must be false on JSON request" );
1705 ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, function( assert
) {
1708 create: function() {
1709 return jQuery
.ajax();
1712 assert
.ok( true, "With no arguments" );
1716 create: function() {
1717 return jQuery
.ajax( baseURL
+ "name.html" );
1720 assert
.ok( true, "With only string URL argument" );
1724 create: function() {
1725 return jQuery
.ajax( baseURL
+ "name.html", {} );
1728 assert
.ok( true, "With string URL param and map" );
1732 create: function( options
) {
1733 return jQuery
.ajax( options
);
1735 url
: baseURL
+ "name.html",
1736 success: function() {
1737 assert
.ok( true, "With only map" );
1743 jQuery
.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain
, label
) {
1744 ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label
, 4, function( assert
) {
1746 url
: baseURL
+ "mock.php?action=jsonp",
1748 crossDomain
: crossDomain
,
1749 beforeSend: function( jqXHR
, s
) {
1750 s
.callback
= s
.jsonpCallback
;
1752 assert
.ok( this.callback
in window
, "JSONP callback name is in the window" );
1754 success: function() {
1755 var previous
= this;
1758 previous
.jsonpCallback
,
1760 "jsonpCallback option is set back to default in callbacks"
1764 !( this.callback
in window
),
1765 "JSONP callback name was removed from the window"
1769 url
: baseURL
+ "mock.php?action=jsonp",
1771 crossDomain
: crossDomain
,
1772 beforeSend: function() {
1773 assert
.strictEqual( this.jsonpCallback
, previous
.callback
, "JSONP callback name is re-used" );
1782 QUnit
.test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", function( assert
) {
1785 var success
= false,
1787 context
.field
= context
;
1789 jQuery
.ajax( "non-existing", {
1791 beforeSend: function() {
1792 assert
.ok( this === context
, "context was not deep extended" );
1800 assert
.ok( success
, "context with circular reference did not generate an exception" );
1803 jQuery
.each( [ "as argument", "in settings object" ], function( inSetting
, title
) {
1805 function request( assert
, url
, test
) {
1807 create: function() {
1808 return jQuery
.ajax( inSetting
? { url
: url
} : url
);
1811 assert
.ok( true, ( test
|| url
) + " " + title
);
1816 ajaxTest( "#10093 - jQuery.ajax() - falsy url " + title
, 4, function( assert
) {
1818 request( assert
, "", "empty string" ),
1819 request( assert
, false ),
1820 request( assert
, null ),
1821 request( assert
, undefined )
1826 ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, function( assert
) {
1828 url
: url( "mock.php?action=error&json=1" ),
1829 dataFilter: function( string
) {
1830 assert
.ok( false, "dataFilter called" );
1833 error: function( jqXHR
) {
1834 assert
.strictEqual( jqXHR
.responseText
, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" );
1835 assert
.deepEqual( jqXHR
.responseJSON
, { code
: 40, message
: "Bad Request" }, "Error body properly parsed" );
1840 ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, function( assert
) {
1842 url
: url( "1x1.jpg" ),
1843 success: function( data
) {
1844 assert
.ok( data
=== undefined || /JFIF/.test( data
), "success callback reached" );
1849 if ( typeof window
.ArrayBuffer
=== "undefined" || typeof new XMLHttpRequest().responseType
!== "string" ) {
1851 QUnit
.skip( "No ArrayBuffer support in XHR", jQuery
.noop
);
1854 // No built-in support for binary data, but it's easy to add via a prefilter
1855 jQuery
.ajaxPrefilter( "arraybuffer", function( s
) {
1856 s
.xhrFields
= { responseType
: "arraybuffer" };
1857 s
.responseFields
.arraybuffer
= "response";
1858 s
.converters
[ "binary arraybuffer" ] = true;
1861 ajaxTest( "gh-2498 - jQuery.ajax() - binary data shouldn't throw an exception", 2, function( assert
) {
1863 url
: url( "1x1.jpg" ),
1864 dataType
: "arraybuffer",
1865 success: function( data
, s
, jqxhr
) {
1866 assert
.ok( data
instanceof window
.ArrayBuffer
, "correct data type" );
1867 assert
.ok( jqxhr
.response
instanceof window
.ArrayBuffer
, "data in jQXHR" );
1873 QUnit
.test( "#11743 - jQuery.ajax() - script, throws exception", function( assert
) {
1875 var done
= assert
.async();
1876 var onerror
= window
.onerror
;
1877 window
.onerror = function() {
1878 assert
.ok( true, "Exception thrown" );
1879 window
.onerror
= onerror
;
1883 url
: baseURL
+ "badjson.js",
1889 jQuery
.each( [ "method", "type" ], function( _
, globalOption
) {
1890 function request( assert
, option
) {
1892 url
: url( "mock.php?action=echoData" ),
1894 success: function( msg
) {
1895 assert
.strictEqual( msg
, "hello", "Check for POST (no override)" );
1899 options
[ option
] = "GET";
1900 options
.success = function( msg
) {
1901 assert
.strictEqual( msg
, "", "Check for no POST (overriding with " + option
+ ")" );
1908 "#12004 - jQuery.ajax() - method is an alias of type - " +
1909 globalOption
+ " set globally", 3,
1910 function( assert
) {
1914 options
[ globalOption
] = "POST";
1915 jQuery
.ajaxSetup( options
);
1918 request( assert
, "type" ),
1919 request( assert
, "method" ),
1927 ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, function( assert
) {
1929 url
: baseURL
+ "dashboard.xml",
1931 success: function( ajaxXML
) {
1932 var parsedXML
= jQuery( jQuery
.parseXML( "<tab title=\"Added\">blibli</tab>" ) ).find( "tab" );
1933 ajaxXML
= jQuery( ajaxXML
);
1935 ajaxXML
.find( "infowindowtab" ).append( parsedXML
);
1937 assert
.strictEqual( e
, undefined, "error" );
1940 assert
.strictEqual( ajaxXML
.find( "tab" ).length
, 3, "Parsed node was added properly" );
1945 ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, function( assert
) {
1947 url
: baseURL
+ "mock.php?action=status&code=204&text=No+Content",
1948 dataType
: "testing",
1950 "* testing": function() {
1951 throw "converter was called";
1954 success: function( data
, status
, jqXHR
) {
1955 assert
.strictEqual( jqXHR
.status
, 204, "status code is 204" );
1956 assert
.strictEqual( status
, "nocontent", "status text is 'nocontent'" );
1957 assert
.strictEqual( data
, undefined, "data is undefined" );
1959 error: function( _
, status
, error
) {
1960 assert
.ok( false, "error" );
1961 assert
.strictEqual( status
, "parsererror", "Parser Error" );
1962 assert
.strictEqual( error
, "converter was called", "Converter was called" );
1967 ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, function( assert
) {
1969 url
: url( "with_fries.xml" ),
1971 success: function( resp
, _
, jqXHR
) {
1972 assert
.notStrictEqual( resp
, undefined, "XML document exists" );
1973 assert
.ok( "responseXML" in jqXHR
, "jqXHR.responseXML exists" );
1974 assert
.strictEqual( resp
, jqXHR
.responseXML
, "jqXHR.responseXML is set correctly" );
1979 ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, function( assert
) {
1981 url
: baseURL
+ "mock.php?action=json",
1987 "text json": function() {
1988 throw "converter was called";
1991 success: function( data
, status
) {
1992 assert
.ok( true, "success" );
1993 assert
.strictEqual( status
, "nocontent", "data is undefined" );
1994 assert
.strictEqual( data
, undefined, "data is undefined" );
1996 error: function( _
, status
, error
) {
1997 assert
.ok( false, "error" );
1998 assert
.strictEqual( status
, "parsererror", "Parser Error" );
1999 assert
.strictEqual( error
, "converter was called", "Converter was called" );
2005 "#14379 - jQuery.ajax() on unload",
2006 "ajax/onunload.html",
2007 function( assert
, jQuery
, window
, document
, status
) {
2009 assert
.strictEqual( status
, "success", "Request completed" );
2013 ajaxTest( "#14683 - jQuery.ajax() - Exceptions thrown synchronously by xhr.send should be caught", 4, function( assert
) {
2015 url
: baseURL
+ "mock.php?action=echoData",
2018 toString: function() {
2019 throw "Can't parse";
2023 done: function( data
) {
2024 assert
.ok( false, "done: " + data
);
2026 fail: function( jqXHR
, status
, error
) {
2027 assert
.ok( true, "exception caught: " + error
);
2028 assert
.strictEqual( jqXHR
.status
, 0, "proper status code" );
2029 assert
.strictEqual( status
, "error", "proper status" );
2032 url
: "http://" + externalHost
+ ":80q",
2033 done: function( data
) {
2034 assert
.ok( false, "done: " + data
);
2036 fail: function( _
, status
, error
) {
2037 assert
.ok( true, "fail: " + status
+ " - " + error
);
2042 ajaxTest( "gh-2587 - when content-type not xml, but looks like one", 1, function( assert
) {
2044 url
: url( "mock.php?action=contentType" ),
2046 contentType
: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
2047 "response": "<test/>"
2049 success: function( result
) {
2053 "Should handle it as a string, not xml"
2059 ajaxTest( "gh-2587 - when content-type not xml, but looks like one", 1, function( assert
) {
2061 url
: url( "mock.php?action=contentType" ),
2063 contentType
: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
2064 "response": "<test/>"
2066 success: function( result
) {
2070 "Should handle it as a string, not xml"
2076 ajaxTest( "gh-2587 - when content-type not json, but looks like one", 1, function( assert
) {
2078 url
: url( "mock.php?action=contentType" ),
2080 contentType
: "test/jsontest",
2081 "response": JSON
.stringify( { test
: "test" } )
2083 success: function( result
) {
2087 "Should handle it as a string, not json"
2093 ajaxTest( "gh-2587 - when content-type not html, but looks like one", 1, function( assert
) {
2095 url
: url( "mock.php?action=contentType" ),
2097 contentType
: "test/htmltest",
2098 "response": "<p>test</p>"
2100 success: function( result
) {
2104 "Should handle it as a string, not html"
2110 ajaxTest( "gh-2587 - when content-type not javascript, but looks like one", 1, function( assert
) {
2112 url
: url( "mock.php?action=contentType" ),
2114 contentType
: "test/testjavascript",
2115 "response": "alert(1)"
2117 success: function( result
) {
2121 "Should handle it as a string, not javascript"
2127 ajaxTest( "gh-2587 - when content-type not ecmascript, but looks like one", 1, function( assert
) {
2129 url
: url( "mock.php?action=contentType" ),
2131 contentType
: "test/testjavascript",
2132 "response": "alert(1)"
2134 success: function( result
) {
2138 "Should handle it as a string, not ecmascript"
2144 //----------- jQuery.ajaxPrefilter()
2146 ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, function( assert
) {
2151 // Ensure prefix does not throw an error
2152 jQuery
.ajaxPrefilter( "+prefix", function( options
, _
, jqXHR
) {
2153 if ( options
.abortInPrefilter
) {
2158 abortInPrefilter
: true,
2160 assert
.ok( false, "error callback called" );
2162 fail: function( _
, reason
) {
2163 assert
.strictEqual( reason
, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" );
2168 //----------- jQuery.ajaxSetup()
2170 QUnit
.test( "jQuery.ajaxSetup()", function( assert
) {
2172 var done
= assert
.async();
2174 url
: url( "mock.php?action=name&name=foo" ),
2175 success: function( msg
) {
2176 assert
.strictEqual( msg
, "bar", "Check for GET" );
2183 QUnit
.test( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", function( assert
) {
2185 var done
= assert
.async();
2188 assert
.ok( passed
++ < 2, "Error callback executed" );
2189 if ( passed
=== 2 ) {
2190 jQuery( document
).off( "ajaxError.setupTest" );
2194 fail = function( a
, b
) {
2195 assert
.ok( false, "Check for timeout failed " + a
+ " " + b
);
2199 jQuery( document
).on( "ajaxError.setupTest", pass
);
2207 url
: url( "mock.php?action=wait&wait=5" ),
2213 QUnit
.test( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", function( assert
) {
2215 var done
= assert
.async();
2222 url
: url( "mock.php?action=wait&wait=1" ),
2224 assert
.ok( false, "Check for local timeout failed" );
2227 success: function() {
2228 assert
.ok( true, "Check for local timeout" );
2234 //----------- jQuery.domManip()
2236 QUnit
.test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", function( assert
) {
2243 jQuery( document
).on( "ajaxStart ajaxStop", function() {
2244 assert
.ok( false, "Global event triggered" );
2247 jQuery( "#qunit-fixture" ).append( "<script src='" + baseURL
+ "mock.php?action=script'></script>" );
2249 jQuery( document
).off( "ajaxStart ajaxStop" );
2253 "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)",
2254 function( assert
) {
2256 var done
= assert
.async();
2262 jQuery( "#qunit-fixture" ).load( baseURL
+ "mock.php?action=echoMethod", function( method
) {
2263 assert
.equal( method
, "GET" );
2270 "jQuery#load() - should resolve with correct context",
2271 function( assert
) {
2273 var done
= assert
.async();
2274 var ps
= jQuery( "<p></p><p></p>" );
2277 ps
.appendTo( "#qunit-fixture" );
2279 ps
.load( baseURL
+ "mock.php?action=echoMethod", function() {
2280 assert
.strictEqual( this, ps
[ i
++ ] );
2290 "#11402 - jQuery.domManip() - script in comments are properly evaluated",
2291 function( assert
) {
2293 jQuery( "#qunit-fixture" ).load( baseURL
+ "cleanScript.html", assert
.async() );
2297 //----------- jQuery.get()
2299 QUnit
.test( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", function( assert
) {
2301 var done
= assert
.async();
2302 jQuery
.get( url( "dashboard.xml" ), function( xml
) {
2304 jQuery( "tab", xml
).each( function() {
2305 content
.push( jQuery( this ).text() );
2307 assert
.strictEqual( content
[ 0 ], "blabla", "Check first tab" );
2308 assert
.strictEqual( content
[ 1 ], "blublu", "Check second tab" );
2313 QUnit
.test( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", function( assert
) {
2315 var done
= assert
.async();
2319 jQuery
.get( url( "mock.php?action=echoQuery" ), function( data
) {
2320 assert
.ok( /helloworld$/.test( data
), "Data from ajaxSettings was used" );
2325 //----------- jQuery.getJSON()
2327 QUnit
.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert
) {
2329 var done
= assert
.async();
2331 url( "mock.php?action=json" ),
2336 assert
.ok( json
.length
>= 2, "Check length" );
2337 assert
.strictEqual( json
[ 0 ][ "name" ], "John", "Check JSON: first, name" );
2338 assert
.strictEqual( json
[ 0 ][ "age" ], 21, "Check JSON: first, age" );
2339 assert
.strictEqual( json
[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
2340 assert
.strictEqual( json
[ 1 ][ "age" ], 25, "Check JSON: second, age" );
2346 QUnit
.test( "jQuery.getJSON( String, Function ) - JSON object", function( assert
) {
2348 var done
= assert
.async();
2349 jQuery
.getJSON( url( "mock.php?action=json" ), function( json
) {
2350 if ( json
&& json
[ "data" ] ) {
2351 assert
.strictEqual( json
[ "data" ][ "lang" ], "en", "Check JSON: lang" );
2352 assert
.strictEqual( json
[ "data" ].length
, 25, "Check JSON: length" );
2358 QUnit
.test( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", function( assert
) {
2360 var done
= assert
.async();
2361 var absoluteUrl
= url( "mock.php?action=json" );
2363 // Make a relative URL absolute relative to the document location
2364 if ( !/^[a-z][a-z0-9+.-]*:/i.test( absoluteUrl
) ) {
2366 // An absolute path replaces everything after the host
2367 if ( absoluteUrl
.charAt( 0 ) === "/" ) {
2368 absoluteUrl
= window
.location
.href
.replace( /(:\/*[^/]*).*$/, "$1" ) + absoluteUrl
;
2370 // A relative path replaces the last slash-separated path segment
2372 absoluteUrl
= window
.location
.href
.replace( /[^/]*$/, "" ) + absoluteUrl
;
2376 jQuery
.getJSON( absoluteUrl
, function( json
) {
2377 assert
.strictEqual( json
.data
.lang
, "en", "Check JSON: lang" );
2378 assert
.strictEqual( json
.data
.length
, 25, "Check JSON: length" );
2383 //----------- jQuery.getScript()
2385 QUnit
.test( "jQuery.getScript( String, Function ) - with callback",
2386 function( assert
) {
2388 var done
= assert
.async();
2390 Globals
.register( "testBar" );
2391 jQuery
.getScript( url( "mock.php?action=testbar" ), function() {
2392 assert
.strictEqual( window
[ "testBar" ], "bar", "Check if script was evaluated" );
2398 QUnit
.test( "jQuery.getScript( String, Function ) - no callback", function( assert
) {
2400 Globals
.register( "testBar" );
2401 jQuery
.getScript( url( "mock.php?action=testbar" ) ).done( assert
.async() );
2404 QUnit
.test( "#8082 - jQuery.getScript( String, Function ) - source as responseText", function( assert
) {
2406 var done
= assert
.async();
2408 Globals
.register( "testBar" );
2409 jQuery
.getScript( url( "mock.php?action=testbar" ), function( data
, _
, jqXHR
) {
2410 assert
.strictEqual( data
, jqXHR
.responseText
, "Same-domain script requests returns the source of the script" );
2415 QUnit
.test( "jQuery.getScript( Object ) - with callback", function( assert
) {
2417 var done
= assert
.async();
2419 Globals
.register( "testBar" );
2421 url
: url( "mock.php?action=testbar" ),
2422 success: function() {
2423 assert
.strictEqual( window
[ "testBar" ], "bar", "Check if script was evaluated" );
2429 QUnit
.test( "jQuery.getScript( Object ) - no callback", function( assert
) {
2431 Globals
.register( "testBar" );
2432 jQuery
.getScript( { url
: url( "mock.php?action=testbar" ) } ).done( assert
.async() );
2435 // //----------- jQuery.fn.load()
2437 // check if load can be called with only url
2438 QUnit
.test( "jQuery.fn.load( String )", function( assert
) {
2441 beforeSend: function() {
2442 assert
.strictEqual( this.type
, "GET", "no data means GET request" );
2445 jQuery( "#first" ).load( baseURL
+ "name.html", assert
.async() );
2448 QUnit
.test( "jQuery.fn.load() - 404 error callbacks", function( assert
) {
2450 var done
= assert
.async();
2452 addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert
)();
2453 jQuery( document
).ajaxStop( done
);
2454 jQuery( "<div/>" ).load( baseURL
+ "404.txt", function() {
2455 assert
.ok( true, "complete" );
2459 // check if load can be called with url and null data
2460 QUnit
.test( "jQuery.fn.load( String, null )", function( assert
) {
2463 beforeSend: function() {
2464 assert
.strictEqual( this.type
, "GET", "no data means GET request" );
2467 jQuery( "#first" ).load( baseURL
+ "name.html", null, assert
.async() );
2470 // check if load can be called with url and undefined data
2471 QUnit
.test( "jQuery.fn.load( String, undefined )", function( assert
) {
2474 beforeSend: function() {
2475 assert
.strictEqual( this.type
, "GET", "no data means GET request" );
2478 jQuery( "#first" ).load( baseURL
+ "name.html", undefined, assert
.async() );
2481 // check if load can be called with only url
2482 QUnit
.test( "jQuery.fn.load( URL_SELECTOR )", function( assert
) {
2484 var done
= assert
.async();
2485 jQuery( "#first" ).load( baseURL
+ "test3.html div.user", function() {
2486 assert
.strictEqual( jQuery( this ).children( "div" ).length
, 2, "Verify that specific elements were injected" );
2491 // Selector should be trimmed to avoid leading spaces (#14773)
2492 QUnit
.test( "jQuery.fn.load( URL_SELECTOR with spaces )", function( assert
) {
2494 var done
= assert
.async();
2495 jQuery( "#first" ).load( baseURL
+ "test3.html #superuser ", function() {
2496 assert
.strictEqual( jQuery( this ).children( "div" ).length
, 1, "Verify that specific elements were injected" );
2501 // Selector should be trimmed to avoid leading spaces (#14773)
2502 // Selector should include any valid non-HTML whitespace (#3003)
2503 QUnit
.test( "jQuery.fn.load( URL_SELECTOR with non-HTML whitespace(#3003) )", function( assert
) {
2505 var done
= assert
.async();
2506 jQuery( "#first" ).load( baseURL
+ "test3.html #whitespace\\\\xA0 ", function() {
2507 assert
.strictEqual( jQuery( this ).children( "div" ).length
, 1, "Verify that specific elements were injected" );
2512 QUnit
.test( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", function( assert
) {
2514 var done
= assert
.async();
2515 jQuery( "#first" ).load( url( "name.html" ), function() {
2516 assert
.ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" );
2521 QUnit
.test( "jQuery.fn.load( String, Function ) - check scripts", function( assert
) {
2523 var done
= assert
.async();
2524 var verifyEvaluation = function() {
2525 assert
.strictEqual( window
[ "testBar" ], "bar", "Check if script src was evaluated after load" );
2526 assert
.strictEqual( jQuery( "#ap" ).html(), "bar", "Check if script evaluation has modified DOM" );
2530 Globals
.register( "testFoo" );
2531 Globals
.register( "testBar" );
2533 jQuery( "#first" ).load( url( "mock.php?action=testHTML&baseURL=" + baseURL
), function() {
2534 assert
.ok( jQuery( "#first" ).html().match( /^html text/ ), "Check content after loading html" );
2535 assert
.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
2536 assert
.strictEqual( window
[ "testFoo" ], "foo", "Check if script was evaluated after load" );
2537 setTimeout( verifyEvaluation
, 600 );
2541 QUnit
.test( "jQuery.fn.load( String, Function ) - check file with only a script tag", function( assert
) {
2543 var done
= assert
.async();
2544 Globals
.register( "testFoo" );
2546 jQuery( "#first" ).load( url( "test2.html" ), function() {
2547 assert
.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
2548 assert
.strictEqual( window
[ "testFoo" ], "foo", "Check if script was evaluated after load" );
2553 QUnit
.test( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", function( assert
) {
2555 var done
= assert
.async();
2557 dataFilter: function() {
2558 return "Hello World";
2561 jQuery( "<div/>" ).load( url( "name.html" ), function( responseText
) {
2562 assert
.strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
2563 assert
.strictEqual( responseText
, "Hello World", "Test callback receives filtered data" );
2568 QUnit
.test( "jQuery.fn.load( String, Object, Function )", function( assert
) {
2570 var done
= assert
.async();
2571 jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), {
2574 var $node
= jQuery( this );
2575 assert
.strictEqual( $node
.find( "#method" ).text(), "POST", "Check method" );
2576 assert
.strictEqual( $node
.find( "#data" ).text(), "bar=ok", "Check if data is passed correctly" );
2581 QUnit
.test( "jQuery.fn.load( String, String, Function )", function( assert
) {
2583 var done
= assert
.async();
2585 jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), "foo=3&bar=ok", function() {
2586 var $node
= jQuery( this );
2587 assert
.strictEqual( $node
.find( "#method" ).text(), "GET", "Check method" );
2588 assert
.ok( $node
.find( "#query" ).text().match( /foo=3&bar=ok/ ), "Check if a string of data is passed correctly" );
2593 QUnit
.test( "jQuery.fn.load() - callbacks get the correct parameters", function( assert
) {
2595 var completeArgs
= {},
2596 done
= assert
.async();
2599 success: function( _
, status
, jqXHR
) {
2600 completeArgs
[ this.url
] = [ jqXHR
.responseText
, status
, jqXHR
];
2602 error: function( jqXHR
, status
) {
2603 completeArgs
[ this.url
] = [ jqXHR
.responseText
, status
, jqXHR
];
2612 url
: baseURL
+ "mock.php?action=echoQuery&arg=pop"
2616 url
: baseURL
+ "404.txt"
2619 function( options
) {
2620 return jQuery
.Deferred( function( defer
) {
2621 jQuery( "#foo" ).load( options
.url
, function() {
2622 var args
= arguments
;
2623 assert
.strictEqual( completeArgs
[ options
.url
].length
, args
.length
, "same number of arguments (" + options
.type
+ ")" );
2624 jQuery
.each( completeArgs
[ options
.url
], function( i
, value
) {
2625 assert
.strictEqual( args
[ i
], value
, "argument #" + i
+ " is the same (" + options
.type
+ ")" );
2634 QUnit
.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", function( assert
) {
2636 var done
= assert
.async();
2641 jQuery( document
).ajaxComplete( function( e
, xml
, s
) {
2642 assert
.strictEqual( s
.dataType
, "html", "Verify the load() dataType was html" );
2643 jQuery( document
).off( "ajaxComplete" );
2646 jQuery( "#first" ).load( baseURL
+ "test3.html" );
2649 QUnit
.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", function( assert
) {
2651 var done
= assert
.async();
2661 jQuery( "#foo" ).load( baseURL
+ "mock.php?action=echoQuery", data
);
2662 jQuery( document
).ajaxComplete( function( event
, jqXHR
, options
) {
2663 assert
.ok( ~options
.data
.indexOf( "foo=bar" ), "Data from ajaxSettings was used" );
2668 // //----------- jQuery.post()
2670 QUnit
.test( "jQuery.post() - data", function( assert
) {
2672 var done
= assert
.async();
2676 url( "mock.php?action=xml" ),
2681 jQuery( "math", xml
).each( function() {
2682 assert
.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2683 assert
.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2688 url
: url( "mock.php?action=echoData" ),
2696 success: function( data
) {
2697 assert
.strictEqual( data
, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" );
2703 QUnit
.test( "jQuery.post( String, Hash, Function ) - simple with xml", function( assert
) {
2705 var done
= assert
.async();
2709 url( "mock.php?action=xml" ),
2714 jQuery( "math", xml
).each( function() {
2715 assert
.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2716 assert
.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2720 jQuery
.post( url( "mock.php?action=xml&cal=5-2" ), {}, function( xml
) {
2721 jQuery( "math", xml
).each( function() {
2722 assert
.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2723 assert
.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2726 ).always( function() {
2731 QUnit
.test( "jQuery[get|post]( options ) - simple with xml", function( assert
) {
2733 var done
= assert
.async();
2735 jQuery
.when
.apply( jQuery
,
2736 jQuery
.map( [ "get", "post" ], function( method
) {
2737 return jQuery
[ method
]( {
2738 url
: url( "mock.php?action=xml" ),
2742 success: function( xml
) {
2743 jQuery( "math", xml
).each( function() {
2744 assert
.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2749 ).always( function() {
2754 //----------- jQuery.active
2756 QUnit
.test( "jQuery.active", function( assert
) {
2758 assert
.ok( jQuery
.active
=== 0, "ajax active counter should be zero: " + jQuery
.active
);