3 var jsonpCallback = this.jsonpCallback = jQuery.ajaxSettings.jsonpCallback;
4 jQuery.ajaxSettings.jsonpCallback = function() {
5 var callback = jsonpCallback.apply( this, arguments );
6 Globals.register( callback );
10 teardown: function() {
11 jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
12 moduleTeardown.apply( this, arguments );
17 test("Unit Testing Environment", 2, function () {
18 ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" );
19 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!)" );
22 if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) {
26 function addGlobalEvents( expected ) {
28 expected = expected || "";
29 jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) {
30 ok( expected.indexOf(e.type) !== -1, e.type );
35 //----------- jQuery.ajax()
37 ajaxTest( "jQuery.ajax() - success callbacks", 8, {
38 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
39 url: url("data/name.html"),
40 beforeSend: function() {
41 ok( true, "beforeSend" );
44 ok( true, "success" );
46 complete: function() {
47 ok( true, "complete");
51 ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, {
52 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
53 create: function( options ) {
54 return jQuery.ajax( url("data/name.html"), options );
56 beforeSend: function() {
57 ok( true, "beforeSend" );
60 ok( true, "success" );
62 complete: function() {
63 ok( true, "complete" );
67 ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, {
68 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
69 url: url("data/name.html"),
70 beforeSend: function() {
71 ok( true, "beforeSend" );
74 afterSend: function( request ) {
75 request.complete(function() {
76 ok( true, "complete" );
77 }).success(function() {
78 ok( true, "success" );
85 ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, {
86 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
87 url: url("data/name.html"),
88 beforeSend: function() {
89 ok( true, "beforeSend" );
92 complete: function( xhr ) {
93 xhr.complete(function() {
94 ok( true, "complete" );
95 }).success(function() {
96 ok( true, "success" );
103 ajaxTest( "jQuery.ajax() - error callbacks", 8, {
104 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError"),
105 url: url("data/name.php?wait=5"),
106 beforeSend: function() {
107 ok( true, "beforeSend" );
109 afterSend: function( request ) {
115 complete: function() {
116 ok( true, "complete" );
120 ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, [
122 url: url("data/name.php?wait=5"),
123 error: function( _, textStatus, errorThrown ) {
124 strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
125 strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" );
127 afterSend: function( request ) {
132 url: url("data/name.php?wait=5"),
133 error: function( _, textStatus, errorThrown ) {
134 strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
135 strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" );
137 afterSend: function( request ) {
138 request.abort("mystatus");
143 ajaxTest( "jQuery.ajax() - responseText on error", 1, {
144 url: url("data/errorWithText.php"),
145 error: function( xhr ) {
146 strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" );
150 asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function() {
154 url: url("data/errorWithText.php"),
160 ok ( true, "Test retrying with jQuery.ajax(this) works" );
162 url: url("data/errorWithText.php"),
166 beforeSend: function() {
167 if ( !previousUrl ) {
168 previousUrl = this.url;
170 strictEqual( this.url, previousUrl, "url parameters are not re-appended" );
184 ajaxTest( "jQuery.ajax() - headers", 5, {
186 jQuery( document ).ajaxSend(function( evt, xhr ) {
187 xhr.setRequestHeader( "ajax-send", "test" );
190 url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send"),
193 "SometHing-elsE": "other value",
194 "OthEr": "something else",
196 "undefined": undefined
199 // Not all browsers allow empty-string headers
200 // https://bugzilla.mozilla.org/show_bug.cgi?id=815299
203 success: function( data, _, xhr ) {
205 requestHeaders = jQuery.extend( this.headers, {
209 for ( i in requestHeaders ) {
210 tmp.push( i, ": ", requestHeaders[ i ] + "", "\n" );
214 strictEqual( data, tmp, "Headers were sent" );
215 strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" );
216 ok( data.indexOf( "undefined" ) < 0 , "Undefined header value was not sent" );
218 emptyHeader = xhr.getResponseHeader("Empty-Header");
219 if ( emptyHeader === null ) {
220 ok( true, "Firefox doesn't support empty headers" );
222 strictEqual( emptyHeader, "", "Empty header received" );
224 strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" );
228 ajaxTest( "jQuery.ajax() - Accept header", 1, {
229 url: url("data/headers.php?keys=accept"),
231 Accept: "very wrong accept value"
233 beforeSend: function( xhr ) {
234 xhr.setRequestHeader("Accept", "*/*");
236 success: function( data ) {
237 strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" );
241 ajaxTest( "jQuery.ajax() - contentType", 2, [
243 url: url("data/headers.php?keys=content-type"),
245 success: function( data ) {
246 strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" );
250 url: url("data/headers.php?keys=content-type"),
252 success: function( data ) {
253 // Some server/interpreter combinations always supply a Content-Type to scripts
254 data = data || "content-type: \n";
255 strictEqual( data, "content-type: \n", "Test content-type is not set when options.contentType===false" );
260 ajaxTest( "jQuery.ajax() - protocol-less urls", 1, {
261 url: "//somedomain.com",
262 beforeSend: function( xhr, settings ) {
263 equal( settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added." );
269 ajaxTest( "jQuery.ajax() - hash", 3, [
271 url: "data/name.html#foo",
272 beforeSend: function( xhr, settings ) {
273 equal( settings.url, "data/name.html", "Make sure that the URL is trimmed." );
279 url: "data/name.html?abc#foo",
280 beforeSend: function( xhr, settings ) {
281 equal( settings.url, "data/name.html?abc", "Make sure that the URL is trimmed." );
287 url: "data/name.html?abc#foo",
291 beforeSend: function( xhr, settings ) {
292 equal( settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed." );
299 ajaxTest( "jQuery.ajax() - cross-domain detection", 7, function() {
300 function request( url, title, crossDomainOrOptions ) {
301 return jQuery.extend( {
304 beforeSend: function( _, s ) {
305 ok( crossDomainOrOptions === false ? !s.crossDomain : s.crossDomain, title );
309 }, crossDomainOrOptions );
312 var loc = document.location,
313 samePort = loc.port || ( loc.protocol === "http:" ? 80 : 443 ),
314 otherPort = loc.port === 666 ? 667 : 666,
315 otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
319 loc.protocol + "//" + loc.host + ":" + samePort,
320 "Test matching ports are not detected as cross-domain",
324 otherProtocol + "//" + loc.host,
325 "Test different protocols are detected as cross-domain"
329 "Adobe AIR app:/ URL detected as cross-domain"
332 loc.protocol + "//example.invalid:" + ( loc.port || 80 ),
333 "Test different hostnames are detected as cross-domain"
336 loc.protocol + "//" + loc.hostname + ":" + otherPort,
337 "Test different ports are detected as cross-domain"
341 "Test about:blank is detected as cross-domain"
344 loc.protocol + "//" + loc.host,
345 "Test forced crossDomain is detected as cross-domain",
353 ajaxTest( "jQuery.ajax() - abort", 9, {
354 setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete"),
355 url: url("data/name.php?wait=5"),
356 beforeSend: function() {
357 ok( true, "beforeSend" );
359 afterSend: function( xhr ) {
360 strictEqual( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
362 strictEqual( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
365 complete: function() {
366 ok( true, "complete" );
370 ajaxTest( "jQuery.ajax() - events with context", 12, function() {
372 var context = document.createElement("div");
374 function event( e ) {
375 equal( this, context, e.type );
378 function callback( msg ) {
380 equal( this, context, "context is preserved on callback " + msg );
386 jQuery( context ).appendTo("#foo")
388 .ajaxComplete( event )
390 .ajaxSuccess( event );
393 url: url("data/name.html"),
395 beforeSend: callback("beforeSend"),
396 success: callback("success"),
397 complete: callback("complete")
399 url: url("data/404.html"),
401 beforeSend: callback("beforeSend"),
402 error: callback("error"),
403 complete: callback("complete")
408 ajaxTest( "jQuery.ajax() - events without context", 3, function() {
409 function nocallback( msg ) {
411 equal( typeof this.url, "string", "context is settings on callback " + msg );
415 url: url("data/404.html"),
416 beforeSend: nocallback("beforeSend"),
417 error: nocallback("error"),
418 complete: nocallback("complete")
422 ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function() {
425 url: url( "data/json.php" ),
427 holder = jQuery.event;
430 complete: function() {
431 ok( true, "Call can be made without jQuery.event" );
432 jQuery.event = holder;
438 ajaxTest( "jQuery.ajax() - context modification", 1, {
439 url: url("data/name.html"),
441 beforeSend: function() {
444 afterSend: function() {
445 strictEqual( this.context.test, "foo", "Make sure the original object is maintained." );
450 ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function() {
457 strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." );
460 url: url("data/name.html"),
461 success: function() {
462 strictEqual( this, obj, "Make sure the original object is maintained." );
465 url: url("data/name.html"),
467 success: function() {
468 ok( this !== obj, "Make sure overriding context is possible." );
474 ajaxTest( "jQuery.ajax() - disabled globals", 3, {
475 setup: addGlobalEvents(""),
477 url: url("data/name.html"),
478 beforeSend: function() {
479 ok( true, "beforeSend" );
481 success: function() {
482 ok( true, "success" );
484 complete: function() {
485 ok( true, "complete" );
489 ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, {
490 url: url("data/with_fries.xml"),
492 success: function( resp ) {
493 equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
494 equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
495 equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
499 ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, {
500 url: url("data/with_fries_over_jsonp.php"),
501 dataType: "jsonp xml",
502 success: function( resp ) {
503 equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
504 equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
505 equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
509 ajaxTest( "jQuery.ajax() - HEAD requests", 2, [
511 url: url("data/name.html"),
513 success: function( data, status, xhr ) {
514 ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" );
518 url: url("data/name.html"),
523 success: function( data, status, xhr ) {
524 ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response with data" );
529 ajaxTest( "jQuery.ajax() - beforeSend", 1, {
530 url: url("data/name.html"),
531 beforeSend: function() {
534 success: function() {
535 ok( this.check, "check beforeSend was executed" );
539 ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, {
542 url: url("data/name.html"),
543 beforeSend: function( xhr ) {
544 ok( true, "beforeSend got called, canceling" );
547 success: function() {
548 ok( false, "request didn't get canceled" );
550 complete: function() {
551 ok( false, "request didn't get canceled" );
554 ok( false, "request didn't get canceled" );
558 fail: function( _, reason ) {
559 strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
563 ajaxTest( "jQuery.ajax() - dataType html", 5, {
565 Globals.register("testFoo");
566 Globals.register("testBar");
569 url: url("data/test.html"),
570 success: function( data ) {
571 ok( data.match( /^html text/ ), "Check content for datatype html" );
572 jQuery("#ap").html( data );
573 strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" );
574 strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" );
578 ajaxTest( "jQuery.ajax() - synchronous request", 1, {
579 url: url("data/json_obj.js"),
583 afterSend: function( xhr ) {
584 ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" );
588 ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, {
589 url: url("data/json_obj.js"),
593 afterSend: function( xhr ) {
595 xhr.done(function( data ) {
596 ok( true, "success callback executed" );
599 ok( /^\{ "data"/.test( result ), "check returned text" );
603 asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() {
604 var target = "data/name.html",
608 success = function() {
611 jQuery( document ).on( "ajaxError.passthru", function( e, xml ) {
613 errorEx += ": " + xml.status;
615 jQuery( document ).one( "ajaxStop", function() {
616 equal( successCount, 5, "Check all ajax calls successful" );
617 equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" );
618 jQuery( document ).off("ajaxError.passthru");
621 Globals.register("testBar");
623 ok( jQuery.get( url(target), success ), "get" );
624 ok( jQuery.post( url(target), success ), "post" );
625 ok( jQuery.getScript( url("data/testbar.php"), success ), "script" );
626 ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" );
633 ajaxTest( "jQuery.ajax() - cache", 12, function() {
635 var re = /_=(.*?)(&|$)/g;
637 function request( url, title ) {
641 beforeSend: function() {
643 while(( tmp = re.exec( this.url ) )) {
644 strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" );
645 parameter = tmp[ 1 ];
646 notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" );
660 "data/text.php?pizza=true",
664 "data/text.php?_=tobereplaced555",
668 "data/text.php?pizza=true&_=tobereplaced555",
672 "data/text.php?_=tobereplaced555&tv=false",
676 "data/text.php?name=David&_=tobereplaced555&washere=true",
677 "2 parameters surrounding _="
682 jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
684 ajaxTest( "jQuery.ajax() - JSONP - Query String (?n)" + label, 4, [
686 url: "data/jsonp.php?callback=?",
688 crossDomain: crossDomain,
689 success: function( data ) {
690 ok( data.data, "JSON results returned (GET, url callback)" );
694 url: "data/jsonp.php?callback=??",
696 crossDomain: crossDomain,
697 success: function( data ) {
698 ok( data.data, "JSON results returned (GET, url context-free callback)" );
702 url: "data/jsonp.php/??",
704 crossDomain: crossDomain,
705 success: function( data ) {
706 ok( data.data, "JSON results returned (GET, REST-like)" );
710 url: "data/jsonp.php/???json=1",
712 crossDomain: crossDomain,
713 success: function( data ) {
714 strictEqual( jQuery.type( data ), "array", "JSON results returned (GET, REST-like with param)" );
719 ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 9, {
721 Globals.register("functionToCleanUp");
722 Globals.register("XXX");
723 Globals.register("jsonpResults");
724 window["jsonpResults"] = function( data ) {
725 ok( data["data"], "JSON results returned (GET, custom callback function)" );
729 url: "data/jsonp.php",
731 crossDomain: crossDomain,
733 success: function( data ) {
734 ok( data["data"], "JSON results returned (GET, data obj callback)" );
737 url: "data/jsonp.php",
739 crossDomain: crossDomain,
740 jsonpCallback: "jsonpResults",
741 success: function( data ) {
742 ok( data.data, "JSON results returned (GET, custom callback name)" );
745 url: "data/jsonp.php",
747 crossDomain: crossDomain,
748 jsonpCallback: "functionToCleanUp",
749 success: function( data ) {
750 ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" );
751 strictEqual( window["functionToCleanUp"], true, "Callback was removed (GET, custom callback name to be cleaned up)" );
754 url: "data/jsonp.php",
756 crossDomain: crossDomain,
757 jsonpCallback: "functionToCleanUp",
758 beforeSend: function( jqXHR ) {
763 xhr.fail(function() {
764 ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
765 strictEqual( window["functionToCleanUp"], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
769 url: "data/jsonp.php?callback=XXX",
772 jsonpCallback: "XXX",
773 crossDomain: crossDomain,
774 beforeSend: function() {
775 ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
777 success: function( data ) {
778 ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
783 ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, [
785 url: "data/jsonp.php",
787 crossDomain: crossDomain,
789 success: function( data ) {
790 ok( data.data, "JSON results returned (GET, data callback)" );
794 url: "data/jsonp.php",
796 crossDomain: crossDomain,
798 success: function( data ) {
799 ok( data.data, "JSON results returned (GET, data context-free callback)" );
805 ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, [
808 url: "data/jsonp.php",
810 crossDomain: crossDomain,
811 success: function( data ) {
812 ok( data["data"], "JSON results returned (POST, no callback)" );
817 url: "data/jsonp.php",
820 crossDomain: crossDomain,
821 success: function( data ) {
822 ok( data["data"], "JSON results returned (POST, data callback)" );
827 url: "data/jsonp.php",
830 crossDomain: crossDomain,
831 success: function( data ) {
832 ok( data["data"], "JSON results returned (POST, data obj callback)" );
837 ajaxTest( "jQuery.ajax() - JSONP" + label, 3, [
839 url: "data/jsonp.php",
841 crossDomain: crossDomain,
842 success: function( data ) {
843 ok( data.data, "JSON results returned (GET, no callback)" );
847 create: function( options ) {
848 var request = jQuery.ajax( options ),
849 promise = request.then(function( data ) {
850 ok( data.data, "first request: JSON results returned (GET, no callback)" );
851 request = jQuery.ajax( this ).done(function( data ) {
852 ok( data.data, "this re-used: JSON results returned (GET, no callback)" );
854 promise.abort = request.abort;
857 promise.abort = request.abort;
860 url: "data/jsonp.php",
862 crossDomain: crossDomain,
869 ajaxTest( "jQuery.ajax() - script, Remote", 2, {
871 Globals.register("testBar");
873 url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php",
875 success: function() {
876 strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
880 ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, {
882 Globals.register("testBar");
884 url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php",
887 success: function( data, status ) {
888 strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" );
889 strictEqual( status, "success", "Script results returned (POST, no callback)" );
893 ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, {
895 Globals.register("testBar");
897 url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/testbar.php",
899 success: function() {
900 strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
904 ajaxTest( "jQuery.ajax() - malformed JSON", 2, {
905 url: "data/badjson.js",
907 error: function( xhr, msg, detailedMsg ) {
908 strictEqual( msg, "parsererror", "A parse error occurred." );
909 ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" );
913 ajaxTest( "jQuery.ajax() - script by content-type", 2, [
915 url: "data/script.php",
922 url: "data/script.php",
930 ajaxTest( "jQuery.ajax() - JSON by content-type", 5, {
931 url: "data/json.php",
936 success: function( json ) {
937 ok( json.length >= 2, "Check length" );
938 strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
939 strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
940 strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
941 strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
945 ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, {
946 url: url("data/json.php"),
954 success: function( text ) {
955 strictEqual( typeof text, "string", "json wasn't auto-determined" );
956 var json = jQuery.parseJSON( text );
957 ok( json.length >= 2, "Check length");
958 strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
959 strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
960 strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
961 strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
965 ajaxTest( "jQuery.ajax() - simple get", 1, {
967 url: url("data/name.php?name=foo"),
968 success: function( msg ) {
969 strictEqual( msg, "bar", "Check for GET" );
973 ajaxTest( "jQuery.ajax() - simple post", 1, {
975 url: url("data/name.php"),
977 success: function( msg ) {
978 strictEqual( msg, "pan", "Check for POST" );
982 ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, {
983 url: "data/echoData.php",
986 success: function( result ) {
987 strictEqual( result, "" );
991 var ifModifiedNow = new Date();
994 /* jQuery.each arguments start */
999 function( label, cache ) {
1000 var isOpera = !!window.opera;
1002 asyncTest( "jQuery.ajax() - If-Modified-Since support" + label, 3, function() {
1003 var url = "data/if_modified_since.php?ts=" + ifModifiedNow++;
1009 success: function( data, status ) {
1010 strictEqual( status, "success" );
1016 success: function( data, status ) {
1017 if ( data === "FAIL" ) {
1018 ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')." );
1019 ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')." );
1021 strictEqual( status, "notmodified" );
1022 ok( data == null, "response body should be empty" );
1027 // Do this because opera simply refuses to implement 304 handling :(
1028 // A feature-driven way of detecting this would be appreciated
1029 // See: http://gist.github.com/599419
1030 ok( isOpera, "error" );
1031 ok( isOpera, "error" );
1037 strictEqual( false, "error" );
1038 // Do this because opera simply refuses to implement 304 handling :(
1039 // A feature-driven way of detecting this would be appreciated
1040 // See: http://gist.github.com/599419
1041 ok( isOpera, "error" );
1047 asyncTest( "jQuery.ajax() - Etag support" + label, 3, function() {
1048 var url = "data/etag.php?ts=" + ifModifiedNow++;
1054 success: function( data, status ) {
1055 strictEqual( status, "success" );
1061 success: function( data, status ) {
1062 if ( data === "FAIL" ) {
1063 ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-None-Match')." );
1064 ok( isOpera, "Opera is incapable of doing .setRequestHeader('If-None-Match')." );
1066 strictEqual( status, "notmodified" );
1067 ok( data == null, "response body should be empty" );
1072 // Do this because opera simply refuses to implement 304 handling :(
1073 // A feature-driven way of detecting this would be appreciated
1074 // See: http://gist.github.com/599419
1075 ok( isOpera, "error" );
1076 ok( isOpera, "error" );
1082 // Do this because opera simply refuses to implement 304 handling :(
1083 // A feature-driven way of detecting this would be appreciated
1084 // See: http://gist.github.com/599419
1085 ok( isOpera, "error" );
1091 /* jQuery.each arguments end */
1094 ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, {
1096 url: "http://example.invalid",
1097 error: function( xhr, _, e ) {
1098 ok( true, "file not found: " + xhr.status + " => " + e );
1102 ajaxTest( "jQuery.ajax() - failing cross-domain", 1, {
1103 url: "http://" + externalHost,
1104 error: function( xhr, _, e ) {
1105 ok( true, "access denied: " + xhr.status + " => " + e );
1109 ajaxTest( "jQuery.ajax() - atom+xml", 1, {
1110 url: url("data/atom+xml.php"),
1111 success: function() {
1112 ok( true, "success" );
1116 asyncTest( "jQuery.ajax() - statusText", 3, function() {
1117 jQuery.ajax( url("data/statusText.php?status=200&text=Hello") ).done(function( _, statusText, jqXHR ) {
1118 strictEqual( statusText, "success", "callback status text ok for success" );
1119 ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" );
1120 jQuery.ajax( url("data/statusText.php?status=404&text=World") ).fail(function( jqXHR, statusText ) {
1121 strictEqual( statusText, "error", "callback status text ok for error" );
1122 // ok( jqXHR.statusText === "World" || jQuery.browser.safari && jqXHR.statusText === "Not Found", "jqXHR status text ok for error (" + jqXHR.statusText + ")" );
1128 asyncTest( "jQuery.ajax() - statusCode", 20, function() {
1132 function countComplete() {
1138 function createStatusCodes( name, isSuccess ) {
1139 name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
1142 ok( isSuccess, name );
1145 ok( !isSuccess, name );
1151 /* jQuery.each arguments start */
1153 "data/name.html": true,
1154 "data/someFileThatDoesNotExist.html": false
1156 function( uri, isSuccess ) {
1158 jQuery.ajax( url(uri), {
1159 statusCode: createStatusCodes( "in options", isSuccess ),
1160 complete: countComplete
1163 jQuery.ajax( url(uri), {
1164 complete: countComplete
1165 }).statusCode( createStatusCodes("immediately with method", isSuccess) );
1167 jQuery.ajax( url(uri), {
1168 complete: function( jqXHR ) {
1169 jqXHR.statusCode( createStatusCodes("on complete", isSuccess) );
1174 jQuery.ajax( url(uri), {
1175 complete: function( jqXHR ) {
1176 setTimeout(function() {
1177 jqXHR.statusCode( createStatusCodes("very late binding", isSuccess) );
1183 jQuery.ajax( url(uri), {
1184 statusCode: createStatusCodes( "all (options)", isSuccess ),
1185 complete: function( jqXHR ) {
1186 jqXHR.statusCode( createStatusCodes("all (on complete)", isSuccess) );
1187 setTimeout(function() {
1188 jqXHR.statusCode( createStatusCodes("all (very late binding)", isSuccess) );
1192 }).statusCode( createStatusCodes("all (immediately with method)", isSuccess) );
1194 var testString = "";
1196 jQuery.ajax( url(uri), {
1197 success: function( a, b, jqXHR ) {
1198 ok( isSuccess, "success" );
1199 var statusCode = {};
1200 statusCode[ jqXHR.status ] = function() {
1203 jqXHR.statusCode( statusCode );
1206 error: function( jqXHR ) {
1207 ok( !isSuccess, "error" );
1208 var statusCode = {};
1209 statusCode[ jqXHR.status ] = function() {
1212 jqXHR.statusCode( statusCode );
1215 complete: function() {
1219 "Test statusCode callbacks are ordered like " + ( isSuccess ? "success" : "error" ) + " callbacks"
1226 /* jQuery.each arguments end*/
1230 ajaxTest( "jQuery.ajax() - transitive conversions", 8, [
1232 url: url("data/json.php"),
1234 "json myJson": function( data ) {
1235 ok( true, "converter called" );
1240 success: function() {
1241 ok( true, "Transitive conversion worked" );
1242 strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text" );
1243 strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType" );
1247 url: url("data/json.php"),
1249 "json myJson": function( data ) {
1250 ok( true, "converter called (*)" );
1254 contents: false, /* headers are wrong so we ignore them */
1255 dataType: "* myJson",
1256 success: function() {
1257 ok( true, "Transitive conversion worked (*)" );
1258 strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text (*)" );
1259 strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType (*)" );
1264 ajaxTest( "jQuery.ajax() - overrideMimeType", 2, [
1266 url: url("data/json.php"),
1267 beforeSend: function( xhr ) {
1268 xhr.overrideMimeType( "application/json" );
1270 success: function( json ) {
1271 ok( json.data, "Mimetype overridden using beforeSend" );
1275 url: url("data/json.php"),
1276 mimeType: "application/json",
1277 success: function( json ) {
1278 ok( json.data, "Mimetype overridden using mimeType option" );
1283 ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, {
1284 url: url("data/echoData.php"),
1285 error: function( _, __, error ) {
1286 equal( typeof error === "object", true, "Didn't get back error object for empty json response" );
1291 ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, {
1292 create: function() {
1293 return jQuery.ajax({
1294 url: url("data/name.html"),
1295 beforeSend: function() {
1296 ok( true, "beforeSend got called, canceling" );
1299 success: function() {
1300 ok( false, "request didn't get canceled" );
1302 complete: function() {
1303 ok( false, "request didn't get canceled" );
1306 ok( false, "request didn't get canceled" );
1310 fail: function( _, reason ) {
1311 strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
1315 ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, {
1316 url: "data/echoQuery.php",
1322 success: function( result ) {
1323 strictEqual( result, "key=value" );
1327 test( "#7531 - jQuery.ajax() - Location object as url", 1, function () {
1332 url: window.location
1339 ok( success, "document.location did not generate exception" );
1342 jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
1343 ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, {
1344 url: "data/jsonp.php",
1346 crossDomain: crossDomain,
1347 beforeSend: function() {
1348 strictEqual( this.cache, false, "cache must be false on JSON request" );
1355 ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, [
1357 create: function() {
1358 return jQuery.ajax();
1361 ok( true, "With no arguments" );
1365 create: function() {
1366 return jQuery.ajax("data/name.html");
1369 ok( true, "With only string URL argument" );
1373 create: function() {
1374 return jQuery.ajax( "data/name.html", {});
1377 ok( true, "With string URL param and map" );
1381 create: function( options ) {
1382 return jQuery.ajax( options );
1384 url: "data/name.html",
1385 success: function() {
1386 ok( true, "With only map" );
1391 jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
1392 ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 2, {
1393 url: "data/jsonp.php",
1395 crossDomain: crossDomain,
1396 beforeSend: function( jqXHR, s ) {
1397 s.callback = s.jsonpCallback;
1399 success: function() {
1400 var previous = this;
1401 strictEqual( previous.jsonpCallback, undefined, "jsonpCallback option is set back to default in callbacks" );
1403 url: "data/jsonp.php",
1405 crossDomain: crossDomain,
1406 beforeSend: function() {
1407 strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" );
1415 test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", 2, function () {
1416 var success = false,
1418 context.field = context;
1420 jQuery.ajax( "non-existing", {
1422 beforeSend: function() {
1423 ok( this === context, "context was not deep extended" );
1431 ok( success, "context with circular reference did not generate an exception" );
1434 jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) {
1436 function request( url, test ) {
1438 create: function() {
1439 return jQuery.ajax( inSetting ? { url: url } : url );
1442 ok( true, ( test || url ) + " " + title );
1447 ajaxTest( "#10093 - jQuery.ajax() - falsy url " + title, 4, [
1448 request( "", "empty string" ),
1451 request( undefined )
1456 ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, {
1457 url: url("data/errorWithJSON.php"),
1458 dataFilter: function( string ) {
1459 ok( false, "dataFilter called" );
1462 error: function( jqXHR ) {
1463 strictEqual( jqXHR.responseText, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" );
1464 deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" );
1468 ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, {
1469 url: url("data/1x1.jpg"),
1470 success: function( data ) {
1471 ok( data === undefined || /JFIF/.test( data ), "success callback reached" );
1475 asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function() {
1476 var onerror = window.onerror;
1477 window.onerror = function() {
1478 ok( true, "Exception thrown" );
1479 window.onerror = onerror;
1483 url: "data/badjson.js",
1489 jQuery.each( [ "method", "type" ], function( _, globalOption ) {
1491 function request( option ) {
1493 url: url("data/echoData.php"),
1495 success: function( msg ) {
1496 strictEqual( msg, "hello", "Check for POST (no override)" );
1500 options[ option ] = "GET";
1501 options.success = function( msg ) {
1502 strictEqual( msg, "", "Check for no POST (overriding with " + option + ")" );
1508 ajaxTest( "#12004 - jQuery.ajax() - method is an alias of type - " + globalOption + " set globally", 3, {
1511 options[ globalOption ] = "POST";
1512 jQuery.ajaxSetup( options );
1523 ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, {
1524 url: "data/dashboard.xml",
1526 success: function( ajaxXML ) {
1527 var parsedXML = jQuery( jQuery.parseXML("<tab title=\"Added\">blibli</tab>") ).find("tab");
1528 ajaxXML = jQuery( ajaxXML );
1530 // Android 2.3 doesn't automatically adopt nodes from foreign documents.
1531 // (see the comment in test/manipulation.js)
1532 // Support: Android 2.3
1533 if ( /android 2\.3/i.test( navigator.userAgent ) ) {
1534 parsedXML = jQuery( ajaxXML[ 0 ].adoptNode( parsedXML[ 0 ] ) );
1536 ajaxXML.find("infowindowtab").append( parsedXML );
1538 strictEqual( e, undefined, "error" );
1541 strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" );
1545 ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, {
1546 url: "data/nocontent.php",
1547 dataType: "testing",
1549 "* testing": function() {
1550 throw "converter was called";
1553 success: function( data, status, jqXHR ) {
1554 strictEqual( jqXHR.status, 204, "status code is 204" );
1555 strictEqual( status, "nocontent", "status text is 'nocontent'" );
1556 strictEqual( data, undefined, "data is undefined" );
1558 error: function( _, status, error ) {
1559 ok( false, "error" );
1560 strictEqual( status, "parsererror", "Parser Error" );
1561 strictEqual( error, "converter was called", "Converter was called" );
1565 ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, {
1566 url: url("data/with_fries.xml"),
1568 success: function( resp, _, jqXHR ) {
1569 notStrictEqual( resp, undefined, "XML document exists" );
1570 ok( "responseXML" in jqXHR, "jqXHR.responseXML exists" );
1571 strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" );
1575 ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, {
1576 url: "data/json.php",
1582 "text json": function() {
1583 throw "converter was called";
1586 success: function( data, status ) {
1587 ok( true, "success" );
1588 strictEqual( status, "nocontent", "data is undefined" );
1589 strictEqual( data, undefined, "data is undefined" );
1591 error: function( _, status, error ) {
1592 ok( false, "error" );
1593 strictEqual( status, "parsererror", "Parser Error" );
1594 strictEqual( error, "converter was called", "Converter was called" );
1598 ajaxTest( "#13240 - jQuery.ajax() - support non-RFC2616 methods", 1, {
1599 url: "data/echoQuery.php",
1601 success: function() {
1602 ok( true, "success" );
1605 ok( false, "error" );
1609 testIframeWithCallback( "#14379 - jQuery.ajax() on unload", "ajax/onunload.html", function( status ) {
1611 strictEqual( status, "success", "Request completed" );
1614 //----------- jQuery.ajaxPrefilter()
1616 ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, {
1619 // Ensure prefix does not throw an error
1620 jQuery.ajaxPrefilter("+prefix", function( options, _, jqXHR ) {
1621 if ( options.abortInPrefilter ) {
1626 abortInPrefilter: true,
1628 ok( false, "error callback called" );
1630 fail: function( _, reason ) {
1631 strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" );
1635 //----------- jQuery.ajaxSetup()
1637 asyncTest( "jQuery.ajaxSetup()", 1, function() {
1639 url: url("data/name.php?name=foo"),
1640 success: function( msg ) {
1641 strictEqual( msg, "bar", "Check for GET" );
1648 asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function() {
1651 ok( passed++ < 2, "Error callback executed" );
1652 if ( passed === 2 ) {
1653 jQuery( document ).off("ajaxError.setupTest");
1657 fail = function( a, b ) {
1658 ok( false, "Check for timeout failed " + a + " " + b );
1662 jQuery( document ).on( "ajaxError.setupTest", pass );
1670 url: url("data/name.php?wait=5"),
1676 asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function() {
1683 url: url("data/name.php?wait=1"),
1685 ok( false, "Check for local timeout failed" );
1688 success: function() {
1689 ok( true, "Check for local timeout" );
1695 //----------- jQuery.domManip()
1697 test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", 1, function() {
1702 jQuery( document ).on( "ajaxStart ajaxStop", function() {
1703 ok( false, "Global event triggered" );
1706 jQuery("#qunit-fixture").append("<script src='data/evalScript.php'></script>");
1708 jQuery( document ).off("ajaxStart ajaxStop");
1711 asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() {
1712 jQuery("#qunit-fixture").load( "data/cleanScript.html", start );
1715 //----------- jQuery.get()
1717 asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function() {
1718 jQuery.get( url("data/dashboard.xml"), function( xml ) {
1720 jQuery( "tab", xml ).each(function() {
1721 content.push( jQuery( this ).text() );
1723 strictEqual( content[ 0 ], "blabla", "Check first tab" );
1724 strictEqual( content[ 1 ], "blublu", "Check second tab" );
1729 asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function() {
1733 jQuery.get( url("data/echoQuery.php"), function( data ) {
1734 ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" );
1739 //----------- jQuery.getJSON()
1741 asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function() {
1743 url("data/json.php"),
1748 ok( json.length >= 2, "Check length" );
1749 strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
1750 strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
1751 strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
1752 strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
1758 asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function() {
1759 jQuery.getJSON( url("data/json.php"), function( json ) {
1760 if ( json && json["data"] ) {
1761 strictEqual( json["data"]["lang"], "en", "Check JSON: lang" );
1762 strictEqual( json["data"].length, 25, "Check JSON: length" );
1768 asyncTest( "jQuery.getJSON() - Using Native JSON", 2, function() {
1769 var restore = "JSON" in window,
1772 Globals.register("JSON");
1776 ok( true, "Verifying that parse method was run" );
1781 jQuery.getJSON( url("data/json.php"), function( json ) {
1782 strictEqual( json, true, "Verifying return value" );
1787 asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function() {
1788 jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) {
1789 strictEqual( json.data.lang, "en", "Check JSON: lang" );
1790 strictEqual( json.data.length, 25, "Check JSON: length" );
1795 //----------- jQuery.getScript()
1797 asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() {
1798 Globals.register("testBar");
1799 jQuery.getScript( url("data/testbar.php"), function() {
1800 strictEqual( window["testBar"], "bar", "Check if script was evaluated" );
1805 asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() {
1806 Globals.register("testBar");
1807 jQuery.getScript( url("data/testbar.php") ).done( start );
1810 asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function() {
1811 Globals.register("testBar");
1812 jQuery.getScript( url("data/testbar.php"), function( data, _, jqXHR ) {
1813 strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" );
1818 //----------- jQuery.fn.load()
1820 // check if load can be called with only url
1821 asyncTest( "jQuery.fn.load( String )", 2, function() {
1823 beforeSend: function() {
1824 strictEqual( this.type, "GET", "no data means GET request" );
1827 jQuery("#first").load( "data/name.html", start );
1830 asyncTest( "jQuery.fn.load() - 404 error callbacks", 6, function() {
1831 addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError")();
1832 jQuery( document ).ajaxStop( start );
1833 jQuery("<div/>").load( "data/404.html", function() {
1834 ok( true, "complete" );
1838 // check if load can be called with url and null data
1839 asyncTest( "jQuery.fn.load( String, null )", 2, function() {
1841 beforeSend: function() {
1842 strictEqual( this.type, "GET", "no data means GET request" );
1845 jQuery("#first").load( "data/name.html", null, start );
1848 // check if load can be called with url and undefined data
1849 asyncTest( "jQuery.fn.load( String, undefined )", 2, function() {
1851 beforeSend: function() {
1852 strictEqual( this.type, "GET", "no data means GET request" );
1855 jQuery("#first").load( "data/name.html", undefined, start );
1858 // check if load can be called with only url
1859 asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function() {
1860 jQuery("#first").load( "data/test3.html div.user", function() {
1861 strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" );
1866 // Selector should be trimmed to avoid leading spaces (#14773)
1867 asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function() {
1868 jQuery("#first").load( "data/test3.html #superuser ", function() {
1869 strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" );
1874 asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() {
1875 jQuery("#first").load( url("data/name.html"), function() {
1876 ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );
1881 asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function() {
1882 var verifyEvaluation = function() {
1883 strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" );
1884 strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
1888 Globals.register("testFoo");
1889 Globals.register("testBar");
1891 jQuery("#first").load( url("data/test.html"), function() {
1892 ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" );
1893 strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" );
1894 strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
1895 setTimeout( verifyEvaluation, 600 );
1899 asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function() {
1900 Globals.register("testFoo");
1902 jQuery("#first").load( url("data/test2.html"), function() {
1903 strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
1904 strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
1909 asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function() {
1911 dataFilter: function() {
1912 return "Hello World";
1915 jQuery("<div/>").load( url("data/name.html"), function( responseText ) {
1916 strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
1917 strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
1922 asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function() {
1923 jQuery("<div />").load( url("data/params_html.php"), {
1927 var $post = jQuery( this ).find("#post");
1928 strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" );
1929 strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" );
1934 asyncTest( "jQuery.fn.load( String, String, Function )", 2, function() {
1935 jQuery("<div />").load( url("data/params_html.php"), "foo=3&bar=ok", function() {
1936 var $get = jQuery( this ).find("#get");
1937 strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" );
1938 strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" );
1943 asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() {
1944 var completeArgs = {};
1947 success: function( _, status, jqXHR ) {
1948 completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
1950 error: function( jqXHR, status ) {
1951 completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
1960 url: "data/echoQuery.php?arg=pop"
1967 function( options ) {
1968 return jQuery.Deferred(function( defer ) {
1969 jQuery("#foo").load( options.url, function() {
1970 var args = arguments;
1971 strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" );
1972 jQuery.each( completeArgs[ options.url ], function( i, value ) {
1973 strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" );
1982 asyncTest( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function() {
1986 jQuery( document ).ajaxComplete(function( e, xml, s ) {
1987 strictEqual( s.dataType, "html", "Verify the load() dataType was html" );
1988 jQuery( document ).off("ajaxComplete");
1991 jQuery("#first").load("data/test3.html");
1994 asyncTest( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function() {
2003 jQuery("#foo").load( "data/echoQuery.php", data );
2004 jQuery( document ).ajaxComplete(function( event, jqXHR, options ) {
2005 ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" );
2010 //----------- jQuery.post()
2012 asyncTest( "jQuery.post() - data", 3, function() {
2015 url("data/name.php"),
2021 jQuery( "math", xml ).each(function() {
2022 strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2023 strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2028 url: url("data/echoData.php"),
2036 success: function( data ) {
2037 strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" );
2040 ).always(function() {
2045 asyncTest( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function() {
2048 url("data/name.php"),
2053 jQuery( "math", xml ).each(function() {
2054 strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2055 strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2059 jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) {
2060 jQuery( "math", xml ).each(function() {
2061 strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
2062 strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
2065 ).always(function() {
2070 //----------- jQuery.active
2072 test( "jQuery.active", 1, function() {
2073 ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );