ajax.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954
  1. module( "ajax", {
  2. setup: function() {
  3. var jsonpCallback = this.jsonpCallback = jQuery.ajaxSettings.jsonpCallback;
  4. jQuery.ajaxSettings.jsonpCallback = function() {
  5. var callback = jsonpCallback.apply( this, arguments );
  6. Globals.register( callback );
  7. return callback;
  8. };
  9. },
  10. teardown: function() {
  11. jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
  12. moduleTeardown.apply( this, arguments );
  13. }
  14. });
  15. (function() {
  16. if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) {
  17. return;
  18. }
  19. function addGlobalEvents( expected ) {
  20. return function() {
  21. expected = expected || "";
  22. jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) {
  23. ok( expected.indexOf(e.type) !== -1, e.type );
  24. });
  25. };
  26. }
  27. //----------- jQuery.ajax()
  28. testIframeWithCallback( "XMLHttpRequest - Attempt to block tests because of dangling XHR requests (IE)", "ajax/unreleasedXHR.html", function() {
  29. expect( 1 );
  30. ok( true, "done" );
  31. });
  32. ajaxTest( "jQuery.ajax() - success callbacks", 8, {
  33. setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
  34. url: url("data/name.html"),
  35. beforeSend: function() {
  36. ok( true, "beforeSend" );
  37. },
  38. success: function() {
  39. ok( true, "success" );
  40. },
  41. complete: function() {
  42. ok( true, "complete");
  43. }
  44. });
  45. ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, {
  46. setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
  47. create: function( options ) {
  48. return jQuery.ajax( url("data/name.html"), options );
  49. },
  50. beforeSend: function() {
  51. ok( true, "beforeSend" );
  52. },
  53. success: function() {
  54. ok( true, "success" );
  55. },
  56. complete: function() {
  57. ok( true, "complete" );
  58. }
  59. });
  60. ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, {
  61. setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
  62. url: url("data/name.html"),
  63. beforeSend: function() {
  64. ok( true, "beforeSend" );
  65. },
  66. success: true,
  67. afterSend: function( request ) {
  68. request.complete(function() {
  69. ok( true, "complete" );
  70. }).success(function() {
  71. ok( true, "success" );
  72. }).error(function() {
  73. ok( false, "error" );
  74. });
  75. }
  76. });
  77. ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, {
  78. setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"),
  79. url: url("data/name.html"),
  80. beforeSend: function() {
  81. ok( true, "beforeSend" );
  82. },
  83. success: true,
  84. complete: function( xhr ) {
  85. xhr.complete(function() {
  86. ok( true, "complete" );
  87. }).success(function() {
  88. ok( true, "success" );
  89. }).error(function() {
  90. ok( false, "error" );
  91. });
  92. }
  93. });
  94. ajaxTest( "jQuery.ajax() - error callbacks", 8, {
  95. setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError"),
  96. url: url("data/name.php?wait=5"),
  97. beforeSend: function() {
  98. ok( true, "beforeSend" );
  99. },
  100. afterSend: function( request ) {
  101. request.abort();
  102. },
  103. error: function() {
  104. ok( true, "error" );
  105. },
  106. complete: function() {
  107. ok( true, "complete" );
  108. }
  109. });
  110. ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, [
  111. {
  112. url: url("data/name.php?wait=5"),
  113. error: function( _, textStatus, errorThrown ) {
  114. strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
  115. strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" );
  116. },
  117. afterSend: function( request ) {
  118. request.abort();
  119. }
  120. },
  121. {
  122. url: url("data/name.php?wait=5"),
  123. error: function( _, textStatus, errorThrown ) {
  124. strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
  125. strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" );
  126. },
  127. afterSend: function( request ) {
  128. request.abort("mystatus");
  129. }
  130. }
  131. ]);
  132. ajaxTest( "jQuery.ajax() - responseText on error", 1, {
  133. url: url("data/errorWithText.php"),
  134. error: function( xhr ) {
  135. strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" );
  136. }
  137. });
  138. asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function() {
  139. var previousUrl,
  140. firstTime = true;
  141. jQuery.ajax({
  142. url: url("data/errorWithText.php"),
  143. error: function() {
  144. if ( firstTime ) {
  145. firstTime = false;
  146. jQuery.ajax( this );
  147. } else {
  148. ok ( true, "Test retrying with jQuery.ajax(this) works" );
  149. jQuery.ajax({
  150. url: url("data/errorWithText.php"),
  151. data: {
  152. "x": 1
  153. },
  154. beforeSend: function() {
  155. if ( !previousUrl ) {
  156. previousUrl = this.url;
  157. } else {
  158. strictEqual( this.url, previousUrl, "url parameters are not re-appended" );
  159. start();
  160. return false;
  161. }
  162. },
  163. error: function() {
  164. jQuery.ajax( this );
  165. }
  166. });
  167. }
  168. }
  169. });
  170. });
  171. ajaxTest( "jQuery.ajax() - headers", 4, {
  172. setup: function() {
  173. jQuery( document ).ajaxSend(function( evt, xhr ) {
  174. xhr.setRequestHeader( "ajax-send", "test" );
  175. });
  176. },
  177. url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_ajax-send"),
  178. headers: {
  179. "siMPle": "value",
  180. "SometHing-elsE": "other value",
  181. "OthEr": "something else"
  182. },
  183. success: function( data, _, xhr ) {
  184. var i, emptyHeader,
  185. requestHeaders = jQuery.extend( this.headers, {
  186. "ajax-send": "test"
  187. }),
  188. tmp = [];
  189. for ( i in requestHeaders ) {
  190. tmp.push( i, ": ", requestHeaders[ i ], "\n" );
  191. }
  192. tmp = tmp.join("");
  193. strictEqual( data, tmp, "Headers were sent" );
  194. strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" );
  195. emptyHeader = xhr.getResponseHeader("Empty-Header");
  196. if ( emptyHeader === null ) {
  197. ok( true, "Firefox doesn't support empty headers" );
  198. } else {
  199. strictEqual( emptyHeader, "", "Empty header received" );
  200. }
  201. strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" );
  202. }
  203. });
  204. ajaxTest( "jQuery.ajax() - Accept header", 1, {
  205. url: url("data/headers.php?keys=accept"),
  206. headers: {
  207. Accept: "very wrong accept value"
  208. },
  209. beforeSend: function( xhr ) {
  210. xhr.setRequestHeader("Accept", "*/*");
  211. },
  212. success: function( data ) {
  213. strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" );
  214. }
  215. });
  216. ajaxTest( "jQuery.ajax() - contentType", 2, [
  217. {
  218. url: url("data/headers.php?keys=content-type"),
  219. contentType: "test",
  220. success: function( data ) {
  221. strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" );
  222. }
  223. },
  224. {
  225. url: url("data/headers.php?keys=content-type"),
  226. contentType: false,
  227. success: function( data ) {
  228. strictEqual( data, "content-type: \n", "Test content-type is not sent when options.contentType===false" );
  229. }
  230. }
  231. ]);
  232. ajaxTest( "jQuery.ajax() - protocol-less urls", 1, {
  233. url: "//somedomain.com",
  234. beforeSend: function( xhr, settings ) {
  235. equal( settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added." );
  236. return false;
  237. },
  238. error: true
  239. });
  240. ajaxTest( "jQuery.ajax() - hash", 3, [
  241. {
  242. url: "data/name.html#foo",
  243. beforeSend: function( xhr, settings ) {
  244. equal( settings.url, "data/name.html", "Make sure that the URL is trimmed." );
  245. return false;
  246. },
  247. error: true
  248. },
  249. {
  250. url: "data/name.html?abc#foo",
  251. beforeSend: function( xhr, settings ) {
  252. equal( settings.url, "data/name.html?abc", "Make sure that the URL is trimmed." );
  253. return false;
  254. },
  255. error: true
  256. },
  257. {
  258. url: "data/name.html?abc#foo",
  259. data: {
  260. "test": 123
  261. },
  262. beforeSend: function( xhr, settings ) {
  263. equal( settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed." );
  264. return false;
  265. },
  266. error: true
  267. }
  268. ]);
  269. ajaxTest( "jQuery.ajax() - cross-domain detection", 7, function() {
  270. function request( url, title, crossDomainOrOptions ) {
  271. return jQuery.extend( {
  272. dataType: "jsonp",
  273. url: url,
  274. beforeSend: function( _, s ) {
  275. ok( crossDomainOrOptions === false ? !s.crossDomain : s.crossDomain, title );
  276. return false;
  277. },
  278. error: true
  279. }, crossDomainOrOptions );
  280. }
  281. var loc = document.location,
  282. samePort = loc.port || ( loc.protocol === "http:" ? 80 : 443 ),
  283. otherPort = loc.port === 666 ? 667 : 666,
  284. otherProtocol = loc.protocol === "http:" ? "https:" : "http:";
  285. return [
  286. request(
  287. loc.protocol + "//" + loc.host + ":" + samePort,
  288. "Test matching ports are not detected as cross-domain",
  289. false
  290. ),
  291. request(
  292. otherProtocol + "//" + loc.host,
  293. "Test different protocols are detected as cross-domain"
  294. ),
  295. request(
  296. "app:/path",
  297. "Adobe AIR app:/ URL detected as cross-domain"
  298. ),
  299. request(
  300. loc.protocol + "//example.invalid:" + ( loc.port || 80 ),
  301. "Test different hostnames are detected as cross-domain"
  302. ),
  303. request(
  304. loc.protocol + "//" + loc.hostname + ":" + otherPort,
  305. "Test different ports are detected as cross-domain"
  306. ),
  307. request(
  308. "about:blank",
  309. "Test about:blank is detected as cross-domain"
  310. ),
  311. request(
  312. loc.protocol + "//" + loc.host,
  313. "Test forced crossDomain is detected as cross-domain",
  314. {
  315. crossDomain: true
  316. }
  317. )
  318. ];
  319. });
  320. ajaxTest( "jQuery.ajax() - abort", 9, {
  321. setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete"),
  322. url: url("data/name.php?wait=5"),
  323. beforeSend: function() {
  324. ok( true, "beforeSend" );
  325. },
  326. afterSend: function( xhr ) {
  327. strictEqual( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
  328. xhr.abort();
  329. strictEqual( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
  330. },
  331. error: true,
  332. complete: function() {
  333. ok( true, "complete" );
  334. }
  335. });
  336. ajaxTest( "jQuery.ajax() - events with context", 12, function() {
  337. var context = document.createElement("div");
  338. function event( e ) {
  339. equal( this, context, e.type );
  340. }
  341. function callback( msg ) {
  342. return function() {
  343. equal( this, context, "context is preserved on callback " + msg );
  344. };
  345. }
  346. return {
  347. setup: function() {
  348. jQuery( context ).appendTo("#foo")
  349. .ajaxSend( event )
  350. .ajaxComplete( event )
  351. .ajaxError( event )
  352. .ajaxSuccess( event );
  353. },
  354. requests: [{
  355. url: url("data/name.html"),
  356. context: context,
  357. beforeSend: callback("beforeSend"),
  358. success: callback("success"),
  359. complete: callback("complete")
  360. }, {
  361. url: url("data/404.html"),
  362. context: context,
  363. beforeSend: callback("beforeSend"),
  364. error: callback("error"),
  365. complete: callback("complete")
  366. }]
  367. };
  368. });
  369. ajaxTest( "jQuery.ajax() - events without context", 3, function() {
  370. function nocallback( msg ) {
  371. return function() {
  372. equal( typeof this.url, "string", "context is settings on callback " + msg );
  373. };
  374. }
  375. return {
  376. url: url("data/404.html"),
  377. beforeSend: nocallback("beforeSend"),
  378. error: nocallback("error"),
  379. complete: nocallback("complete")
  380. };
  381. });
  382. ajaxTest( "jQuery.ajax() - context modification", 1, {
  383. url: url("data/name.html"),
  384. context: {},
  385. beforeSend: function() {
  386. this.test = "foo";
  387. },
  388. afterSend: function() {
  389. strictEqual( this.context.test, "foo", "Make sure the original object is maintained." );
  390. },
  391. success: true
  392. });
  393. ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function() {
  394. var obj = {};
  395. return {
  396. setup: function() {
  397. jQuery.ajaxSetup({
  398. context: obj
  399. });
  400. strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." );
  401. },
  402. requests: [{
  403. url: url("data/name.html"),
  404. success: function() {
  405. strictEqual( this, obj, "Make sure the original object is maintained." );
  406. }
  407. }, {
  408. url: url("data/name.html"),
  409. context: {},
  410. success: function() {
  411. ok( this !== obj, "Make sure overriding context is possible." );
  412. }
  413. }]
  414. };
  415. });
  416. ajaxTest( "jQuery.ajax() - disabled globals", 3, {
  417. setup: addGlobalEvents(""),
  418. global: false,
  419. url: url("data/name.html"),
  420. beforeSend: function() {
  421. ok( true, "beforeSend" );
  422. },
  423. success: function() {
  424. ok( true, "success" );
  425. },
  426. complete: function() {
  427. ok( true, "complete" );
  428. }
  429. });
  430. ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, {
  431. url: url("data/with_fries.xml"),
  432. dataType: "xml",
  433. success: function( resp ) {
  434. equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
  435. equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
  436. equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
  437. }
  438. });
  439. ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, {
  440. url: url("data/with_fries_over_jsonp.php"),
  441. dataType: "jsonp xml",
  442. success: function( resp ) {
  443. equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
  444. equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
  445. equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
  446. }
  447. });
  448. ajaxTest( "jQuery.ajax() - HEAD requests", 2, [
  449. {
  450. url: url("data/name.html"),
  451. type: "HEAD",
  452. success: function( data, status, xhr ) {
  453. ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" );
  454. }
  455. },
  456. {
  457. url: url("data/name.html"),
  458. data: {
  459. "whip_it": "good"
  460. },
  461. type: "HEAD",
  462. success: function( data, status, xhr ) {
  463. ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response with data" );
  464. }
  465. }
  466. ]);
  467. ajaxTest( "jQuery.ajax() - beforeSend", 1, {
  468. url: url("data/name.html"),
  469. beforeSend: function() {
  470. this.check = true;
  471. },
  472. success: function() {
  473. ok( this.check, "check beforeSend was executed" );
  474. }
  475. });
  476. ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, {
  477. create: function() {
  478. return jQuery.ajax({
  479. url: url("data/name.html"),
  480. beforeSend: function( xhr ) {
  481. ok( true, "beforeSend got called, canceling" );
  482. xhr.abort();
  483. },
  484. success: function() {
  485. ok( false, "request didn't get canceled" );
  486. },
  487. complete: function() {
  488. ok( false, "request didn't get canceled" );
  489. },
  490. error: function() {
  491. ok( false, "request didn't get canceled" );
  492. }
  493. });
  494. },
  495. fail: function( _, reason ) {
  496. strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
  497. }
  498. });
  499. ajaxTest( "jQuery.ajax() - dataType html", 5, {
  500. setup: function() {
  501. Globals.register("testFoo");
  502. Globals.register("testBar");
  503. },
  504. dataType: "html",
  505. url: url("data/test.html"),
  506. success: function( data ) {
  507. ok( data.match( /^html text/ ), "Check content for datatype html" );
  508. jQuery("#ap").html( data );
  509. strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" );
  510. strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" );
  511. }
  512. });
  513. ajaxTest( "jQuery.ajax() - synchronous request", 1, {
  514. url: url("data/json_obj.js"),
  515. dataType: "text",
  516. async: false,
  517. success: true,
  518. afterSend: function( xhr ) {
  519. ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" );
  520. }
  521. });
  522. ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, {
  523. url: url("data/json_obj.js"),
  524. async: false,
  525. dataType: "text",
  526. success: true,
  527. afterSend: function( xhr ) {
  528. var result;
  529. xhr.done(function( data ) {
  530. ok( true, "success callback executed" );
  531. result = data;
  532. });
  533. ok( /^\{ "data"/.test( result ), "check returned text" );
  534. }
  535. });
  536. asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() {
  537. var target = "data/name.html",
  538. successCount = 0,
  539. errorCount = 0,
  540. errorEx = "",
  541. success = function() {
  542. successCount++;
  543. };
  544. jQuery( document ).on( "ajaxError.passthru", function( e, xml ) {
  545. errorCount++;
  546. errorEx += ": " + xml.status;
  547. });
  548. jQuery( document ).one( "ajaxStop", function() {
  549. equal( successCount, 5, "Check all ajax calls successful" );
  550. equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" );
  551. jQuery( document ).off("ajaxError.passthru");
  552. start();
  553. });
  554. Globals.register("testBar");
  555. ok( jQuery.get( url(target), success ), "get" );
  556. ok( jQuery.post( url(target), success ), "post" );
  557. ok( jQuery.getScript( url("data/test.js"), success ), "script" );
  558. ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" );
  559. ok( jQuery.ajax({
  560. url: url( target ),
  561. success: success
  562. }), "generic" );
  563. });
  564. ajaxTest( "jQuery.ajax() - cache", 12, function() {
  565. var re = /_=(.*?)(&|$)/g;
  566. function request( url, title ) {
  567. return {
  568. url: url,
  569. cache: false,
  570. beforeSend: function() {
  571. var parameter, tmp;
  572. while(( tmp = re.exec( this.url ) )) {
  573. strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" );
  574. parameter = tmp[ 1 ];
  575. notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" );
  576. }
  577. return false;
  578. },
  579. error: true
  580. };
  581. }
  582. return [
  583. request(
  584. "data/text.php",
  585. "no parameter"
  586. ),
  587. request(
  588. "data/text.php?pizza=true",
  589. "1 parameter"
  590. ),
  591. request(
  592. "data/text.php?_=tobereplaced555",
  593. "_= parameter"
  594. ),
  595. request(
  596. "data/text.php?pizza=true&_=tobereplaced555",
  597. "1 parameter and _="
  598. ),
  599. request(
  600. "data/text.php?_=tobereplaced555&tv=false",
  601. "_= and 1 parameter"
  602. ),
  603. request(
  604. "data/text.php?name=David&_=tobereplaced555&washere=true",
  605. "2 parameters surrounding _="
  606. )
  607. ];
  608. });
  609. jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
  610. ajaxTest( "jQuery.ajax() - JSONP - Query String (?n)" + label, 4, [
  611. {
  612. url: "data/jsonp.php?callback=?",
  613. dataType: "jsonp",
  614. crossDomain: crossDomain,
  615. success: function( data ) {
  616. ok( data.data, "JSON results returned (GET, url callback)" );
  617. }
  618. },
  619. {
  620. url: "data/jsonp.php?callback=??",
  621. dataType: "jsonp",
  622. crossDomain: crossDomain,
  623. success: function( data ) {
  624. ok( data.data, "JSON results returned (GET, url context-free callback)" );
  625. }
  626. },
  627. {
  628. url: "data/jsonp.php/??",
  629. dataType: "jsonp",
  630. crossDomain: crossDomain,
  631. success: function( data ) {
  632. ok( data.data, "JSON results returned (GET, REST-like)" );
  633. }
  634. },
  635. {
  636. url: "data/jsonp.php/???json=1",
  637. dataType: "jsonp",
  638. crossDomain: crossDomain,
  639. success: function( data ) {
  640. strictEqual( jQuery.type( data ), "array", "JSON results returned (GET, REST-like with param)" );
  641. }
  642. }
  643. ]);
  644. ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 9, {
  645. setup: function() {
  646. Globals.register("functionToCleanUp");
  647. Globals.register("XXX");
  648. Globals.register("jsonpResults");
  649. window["jsonpResults"] = function( data ) {
  650. ok( data["data"], "JSON results returned (GET, custom callback function)" );
  651. };
  652. },
  653. requests: [{
  654. url: "data/jsonp.php",
  655. dataType: "jsonp",
  656. crossDomain: crossDomain,
  657. jsonp: "callback",
  658. success: function( data ) {
  659. ok( data["data"], "JSON results returned (GET, data obj callback)" );
  660. }
  661. }, {
  662. url: "data/jsonp.php",
  663. dataType: "jsonp",
  664. crossDomain: crossDomain,
  665. jsonpCallback: "jsonpResults",
  666. success: function( data ) {
  667. ok( data.data, "JSON results returned (GET, custom callback name)" );
  668. }
  669. }, {
  670. url: "data/jsonp.php",
  671. dataType: "jsonp",
  672. crossDomain: crossDomain,
  673. jsonpCallback: "functionToCleanUp",
  674. success: function( data ) {
  675. ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" );
  676. strictEqual( window["functionToCleanUp"], undefined, "Callback was removed (GET, custom callback name to be cleaned up)" );
  677. var xhr;
  678. jQuery.ajax({
  679. url: "data/jsonp.php",
  680. dataType: "jsonp",
  681. crossDomain: crossDomain,
  682. jsonpCallback: "functionToCleanUp",
  683. beforeSend: function( jqXHR ) {
  684. xhr = jqXHR;
  685. return false;
  686. }
  687. });
  688. xhr.fail(function() {
  689. ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
  690. strictEqual( window["functionToCleanUp"], undefined, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
  691. });
  692. }
  693. }, {
  694. url: "data/jsonp.php?callback=XXX",
  695. dataType: "jsonp",
  696. jsonp: false,
  697. jsonpCallback: "XXX",
  698. crossDomain: crossDomain,
  699. beforeSend: function() {
  700. ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
  701. },
  702. success: function( data ) {
  703. ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
  704. }
  705. }]
  706. });
  707. ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, [
  708. {
  709. url: "data/jsonp.php",
  710. dataType: "jsonp",
  711. crossDomain: crossDomain,
  712. data: "callback=?",
  713. success: function( data ) {
  714. ok( data.data, "JSON results returned (GET, data callback)" );
  715. }
  716. },
  717. {
  718. url: "data/jsonp.php",
  719. dataType: "jsonp",
  720. crossDomain: crossDomain,
  721. data: "callback=??",
  722. success: function( data ) {
  723. ok( data.data, "JSON results returned (GET, data context-free callback)" );
  724. }
  725. }
  726. ]);
  727. ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, [
  728. {
  729. type: "POST",
  730. url: "data/jsonp.php",
  731. dataType: "jsonp",
  732. crossDomain: crossDomain,
  733. success: function( data ) {
  734. ok( data["data"], "JSON results returned (POST, no callback)" );
  735. }
  736. },
  737. {
  738. type: "POST",
  739. url: "data/jsonp.php",
  740. data: "callback=?",
  741. dataType: "jsonp",
  742. crossDomain: crossDomain,
  743. success: function( data ) {
  744. ok( data["data"], "JSON results returned (POST, data callback)" );
  745. }
  746. },
  747. {
  748. type: "POST",
  749. url: "data/jsonp.php",
  750. jsonp: "callback",
  751. dataType: "jsonp",
  752. crossDomain: crossDomain,
  753. success: function( data ) {
  754. ok( data["data"], "JSON results returned (POST, data obj callback)" );
  755. }
  756. }
  757. ]);
  758. ajaxTest( "jQuery.ajax() - JSONP" + label, 3, [
  759. {
  760. url: "data/jsonp.php",
  761. dataType: "jsonp",
  762. crossDomain: crossDomain,
  763. success: function( data ) {
  764. ok( data.data, "JSON results returned (GET, no callback)" );
  765. }
  766. },
  767. {
  768. create: function( options ) {
  769. var request = jQuery.ajax( options ),
  770. promise = request.then(function( data ) {
  771. ok( data.data, "first request: JSON results returned (GET, no callback)" );
  772. request = jQuery.ajax( this ).done(function( data ) {
  773. ok( data.data, "this re-used: JSON results returned (GET, no callback)" );
  774. });
  775. promise.abort = request.abort;
  776. return request;
  777. });
  778. promise.abort = request.abort;
  779. return promise;
  780. },
  781. url: "data/jsonp.php",
  782. dataType: "jsonp",
  783. crossDomain: crossDomain,
  784. success: true
  785. }
  786. ]);
  787. });
  788. ajaxTest( "jQuery.ajax() - script, Remote", 2, {
  789. setup: function() {
  790. Globals.register("testBar");
  791. },
  792. url: window.location.href.replace( /[^\/]*$/, "" ) + "data/test.js",
  793. dataType: "script",
  794. success: function() {
  795. strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
  796. }
  797. });
  798. ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, {
  799. setup: function() {
  800. Globals.register("testBar");
  801. },
  802. url: window.location.href.replace( /[^\/]*$/, "" ) + "data/test.js",
  803. type: "POST",
  804. dataType: "script",
  805. success: function( data, status ) {
  806. strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" );
  807. strictEqual( status, "success", "Script results returned (POST, no callback)" );
  808. }
  809. });
  810. ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, {
  811. setup: function() {
  812. Globals.register("testBar");
  813. },
  814. url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/test.js",
  815. dataType: "script",
  816. success: function() {
  817. strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
  818. }
  819. });
  820. ajaxTest( "jQuery.ajax() - malformed JSON", 2, {
  821. url: "data/badjson.js",
  822. dataType: "json",
  823. error: function( xhr, msg, detailedMsg ) {
  824. strictEqual( msg, "parsererror", "A parse error occurred." );
  825. ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" );
  826. }
  827. });
  828. ajaxTest( "jQuery.ajax() - script by content-type", 2, [
  829. {
  830. url: "data/script.php",
  831. data: {
  832. "header": "script"
  833. },
  834. success: true
  835. },
  836. {
  837. url: "data/script.php",
  838. data: {
  839. "header": "ecma"
  840. },
  841. success: true
  842. }
  843. ]);
  844. ajaxTest( "jQuery.ajax() - JSON by content-type", 5, {
  845. url: "data/json.php",
  846. data: {
  847. "header": "json",
  848. "json": "array"
  849. },
  850. success: function( json ) {
  851. ok( json.length >= 2, "Check length" );
  852. strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
  853. strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
  854. strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
  855. strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
  856. }
  857. });
  858. ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, {
  859. url: url("data/json.php"),
  860. data: {
  861. "header": "json",
  862. "json": "array"
  863. },
  864. contents: {
  865. "json": false
  866. },
  867. success: function( text ) {
  868. strictEqual( typeof text, "string", "json wasn't auto-determined" );
  869. var json = jQuery.parseJSON( text );
  870. ok( json.length >= 2, "Check length");
  871. strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
  872. strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
  873. strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
  874. strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
  875. }
  876. });
  877. ajaxTest( "jQuery.ajax() - simple get", 1, {
  878. type: "GET",
  879. url: url("data/name.php?name=foo"),
  880. success: function( msg ) {
  881. strictEqual( msg, "bar", "Check for GET" );
  882. }
  883. });
  884. ajaxTest( "jQuery.ajax() - simple post", 1, {
  885. type: "POST",
  886. url: url("data/name.php"),
  887. data: "name=peter",
  888. success: function( msg ) {
  889. strictEqual( msg, "pan", "Check for POST" );
  890. }
  891. });
  892. ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, {
  893. url: "data/echoData.php",
  894. data: undefined,
  895. type: "post",
  896. success: function( result ) {
  897. strictEqual( result, "" );
  898. }
  899. });
  900. var ifModifiedNow = new Date();
  901. jQuery.each(
  902. /* jQuery.each arguments start */
  903. {
  904. " (cache)": true,
  905. " (no cache)": false
  906. },
  907. function( label, cache ) {
  908. // Support: Opera 12.0
  909. // In Opera 12.0, XHR doesn't notify 304 back to the user properly
  910. var opera = window.opera && window.opera.version();
  911. jQuery.each(
  912. {
  913. "If-Modified-Since": "if_modified_since.php",
  914. "Etag": "etag.php"
  915. },
  916. function( type, url ) {
  917. url = "data/" + url + "?ts=" + ifModifiedNow++;
  918. asyncTest( "jQuery.ajax() - " + type + " support" + label, 4, function() {
  919. jQuery.ajax({
  920. url: url,
  921. ifModified: true,
  922. cache: cache,
  923. success: function( _, status ) {
  924. strictEqual( status, "success", "Initial status is 'success'" );
  925. jQuery.ajax({
  926. url: url,
  927. ifModified: true,
  928. cache: cache,
  929. success: function( data, status, jqXHR ) {
  930. if ( status === "success" && opera === "12.00" ) {
  931. strictEqual( status, "success", "Opera 12.0: Following status is 'success'" );
  932. strictEqual( jqXHR.status, 200, "Opera 12.0: XHR status is 200, not 304" );
  933. strictEqual( data, "", "Opera 12.0: response body is empty" );
  934. } else {
  935. strictEqual( status, "notmodified", "Following status is 'notmodified'" );
  936. strictEqual( jqXHR.status, 304, "XHR status is 304" );
  937. equal( data, null, "no response body is given" );
  938. }
  939. },
  940. complete: function() {
  941. start();
  942. }
  943. });
  944. }
  945. });
  946. });
  947. }
  948. );
  949. }
  950. /* jQuery.each arguments end */
  951. );
  952. ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, {
  953. // see RFC 2606
  954. url: "http://example.invalid",
  955. error: function( xhr, _, e ) {
  956. ok( true, "file not found: " + xhr.status + " => " + e );
  957. }
  958. });
  959. ajaxTest( "jQuery.ajax() - failing cross-domain", 1, {
  960. url: "http://" + externalHost,
  961. error: function( xhr, _, e ) {
  962. ok( true, "access denied: " + xhr.status + " => " + e );
  963. }
  964. });
  965. ajaxTest( "jQuery.ajax() - atom+xml", 1, {
  966. url: url("data/atom+xml.php"),
  967. success: function() {
  968. ok( true, "success" );
  969. }
  970. });
  971. asyncTest( "jQuery.ajax() - statusText", 3, function() {
  972. jQuery.ajax( url("data/statusText.php?status=200&text=Hello") ).done(function( _, statusText, jqXHR ) {
  973. strictEqual( statusText, "success", "callback status text ok for success" );
  974. ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" );
  975. jQuery.ajax( url("data/statusText.php?status=404&text=World") ).fail(function( jqXHR, statusText ) {
  976. strictEqual( statusText, "error", "callback status text ok for error" );
  977. start();
  978. });
  979. });
  980. });
  981. asyncTest( "jQuery.ajax() - statusCode", 20, function() {
  982. var count = 12;
  983. function countComplete() {
  984. if ( ! --count ) {
  985. start();
  986. }
  987. }
  988. function createStatusCodes( name, isSuccess ) {
  989. name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
  990. return {
  991. 200: function() {
  992. ok( isSuccess, name );
  993. },
  994. 404: function() {
  995. ok( !isSuccess, name );
  996. }
  997. };
  998. }
  999. jQuery.each(
  1000. /* jQuery.each arguments start */
  1001. {
  1002. "data/name.html": true,
  1003. "data/someFileThatDoesNotExist.html": false
  1004. },
  1005. function( uri, isSuccess ) {
  1006. jQuery.ajax( url(uri), {
  1007. statusCode: createStatusCodes( "in options", isSuccess ),
  1008. complete: countComplete
  1009. });
  1010. jQuery.ajax( url(uri), {
  1011. complete: countComplete
  1012. }).statusCode( createStatusCodes("immediately with method", isSuccess) );
  1013. jQuery.ajax( url(uri), {
  1014. complete: function( jqXHR ) {
  1015. jqXHR.statusCode( createStatusCodes("on complete", isSuccess) );
  1016. countComplete();
  1017. }
  1018. });
  1019. jQuery.ajax( url(uri), {
  1020. complete: function( jqXHR ) {
  1021. setTimeout(function() {
  1022. jqXHR.statusCode( createStatusCodes("very late binding", isSuccess) );
  1023. countComplete();
  1024. }, 100 );
  1025. }
  1026. });
  1027. jQuery.ajax( url(uri), {
  1028. statusCode: createStatusCodes( "all (options)", isSuccess ),
  1029. complete: function( jqXHR ) {
  1030. jqXHR.statusCode( createStatusCodes("all (on complete)", isSuccess) );
  1031. setTimeout(function() {
  1032. jqXHR.statusCode( createStatusCodes("all (very late binding)", isSuccess) );
  1033. countComplete();
  1034. }, 100 );
  1035. }
  1036. }).statusCode( createStatusCodes("all (immediately with method)", isSuccess) );
  1037. var testString = "";
  1038. jQuery.ajax( url(uri), {
  1039. success: function( a, b, jqXHR ) {
  1040. ok( isSuccess, "success" );
  1041. var statusCode = {};
  1042. statusCode[ jqXHR.status ] = function() {
  1043. testString += "B";
  1044. };
  1045. jqXHR.statusCode( statusCode );
  1046. testString += "A";
  1047. },
  1048. error: function( jqXHR ) {
  1049. ok( !isSuccess, "error" );
  1050. var statusCode = {};
  1051. statusCode[ jqXHR.status ] = function() {
  1052. testString += "B";
  1053. };
  1054. jqXHR.statusCode( statusCode );
  1055. testString += "A";
  1056. },
  1057. complete: function() {
  1058. strictEqual(
  1059. testString,
  1060. "AB",
  1061. "Test statusCode callbacks are ordered like " + ( isSuccess ? "success" : "error" ) + " callbacks"
  1062. );
  1063. countComplete();
  1064. }
  1065. });
  1066. }
  1067. /* jQuery.each arguments end*/
  1068. );
  1069. });
  1070. ajaxTest( "jQuery.ajax() - transitive conversions", 8, [
  1071. {
  1072. url: url("data/json.php"),
  1073. converters: {
  1074. "json myJson": function( data ) {
  1075. ok( true, "converter called" );
  1076. return data;
  1077. }
  1078. },
  1079. dataType: "myJson",
  1080. success: function() {
  1081. ok( true, "Transitive conversion worked" );
  1082. strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text" );
  1083. strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType" );
  1084. }
  1085. },
  1086. {
  1087. url: url("data/json.php"),
  1088. converters: {
  1089. "json myJson": function( data ) {
  1090. ok( true, "converter called (*)" );
  1091. return data;
  1092. }
  1093. },
  1094. contents: false, /* headers are wrong so we ignore them */
  1095. dataType: "* myJson",
  1096. success: function() {
  1097. ok( true, "Transitive conversion worked (*)" );
  1098. strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text (*)" );
  1099. strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType (*)" );
  1100. }
  1101. }
  1102. ]);
  1103. ajaxTest( "jQuery.ajax() - overrideMimeType", 2, [
  1104. {
  1105. url: url("data/json.php"),
  1106. beforeSend: function( xhr ) {
  1107. xhr.overrideMimeType( "application/json" );
  1108. },
  1109. success: function( json ) {
  1110. ok( json.data, "Mimetype overridden using beforeSend" );
  1111. }
  1112. },
  1113. {
  1114. url: url("data/json.php"),
  1115. mimeType: "application/json",
  1116. success: function( json ) {
  1117. ok( json.data, "Mimetype overridden using mimeType option" );
  1118. }
  1119. }
  1120. ]);
  1121. ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, {
  1122. url: url("data/echoData.php"),
  1123. error: function( _, __, error ) {
  1124. equal( typeof error === "object", true, "Didn't get back error object for empty json response" );
  1125. },
  1126. dataType: "json"
  1127. });
  1128. ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, {
  1129. create: function() {
  1130. return jQuery.ajax({
  1131. url: url("data/name.html"),
  1132. beforeSend: function() {
  1133. ok( true, "beforeSend got called, canceling" );
  1134. return false;
  1135. },
  1136. success: function() {
  1137. ok( false, "request didn't get canceled" );
  1138. },
  1139. complete: function() {
  1140. ok( false, "request didn't get canceled" );
  1141. },
  1142. error: function() {
  1143. ok( false, "request didn't get canceled" );
  1144. }
  1145. });
  1146. },
  1147. fail: function( _, reason ) {
  1148. strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
  1149. }
  1150. });
  1151. ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, {
  1152. url: "data/echoQuery.php",
  1153. data: {
  1154. key: function() {
  1155. return "value";
  1156. }
  1157. },
  1158. success: function( result ) {
  1159. strictEqual( result, "key=value" );
  1160. }
  1161. });
  1162. test( "#7531 - jQuery.ajax() - Location object as url", 1, function () {
  1163. var xhr,
  1164. success = false;
  1165. try {
  1166. xhr = jQuery.ajax({
  1167. url: window.location
  1168. });
  1169. success = true;
  1170. xhr.abort();
  1171. } catch (e) {
  1172. }
  1173. ok( success, "document.location did not generate exception" );
  1174. });
  1175. jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
  1176. ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, {
  1177. url: "data/jsonp.php",
  1178. dataType: "jsonp",
  1179. crossDomain: crossDomain,
  1180. beforeSend: function() {
  1181. strictEqual( this.cache, false, "cache must be false on JSON request" );
  1182. return false;
  1183. },
  1184. error: true
  1185. });
  1186. });
  1187. ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, [
  1188. {
  1189. create: function() {
  1190. return jQuery.ajax();
  1191. },
  1192. done: function() {
  1193. ok( true, "With no arguments" );
  1194. }
  1195. },
  1196. {
  1197. create: function() {
  1198. return jQuery.ajax("data/name.html");
  1199. },
  1200. done: function() {
  1201. ok( true, "With only string URL argument" );
  1202. }
  1203. },
  1204. {
  1205. create: function() {
  1206. return jQuery.ajax( "data/name.html", {});
  1207. },
  1208. done: function() {
  1209. ok( true, "With string URL param and map" );
  1210. }
  1211. },
  1212. {
  1213. create: function( options ) {
  1214. return jQuery.ajax( options );
  1215. },
  1216. url: "data/name.html",
  1217. success: function() {
  1218. ok( true, "With only map" );
  1219. }
  1220. }
  1221. ]);
  1222. jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
  1223. ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 2, {
  1224. url: "data/jsonp.php",
  1225. dataType: "jsonp",
  1226. crossDomain: crossDomain,
  1227. beforeSend: function( jqXHR, s ) {
  1228. s.callback = s.jsonpCallback;
  1229. },
  1230. success: function() {
  1231. var previous = this;
  1232. strictEqual( previous.jsonpCallback, undefined, "jsonpCallback option is set back to default in callbacks" );
  1233. jQuery.ajax({
  1234. url: "data/jsonp.php",
  1235. dataType: "jsonp",
  1236. crossDomain: crossDomain,
  1237. beforeSend: function() {
  1238. strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" );
  1239. return false;
  1240. }
  1241. });
  1242. }
  1243. });
  1244. });
  1245. test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", 2, function () {
  1246. var success = false,
  1247. context = {};
  1248. context.field = context;
  1249. try {
  1250. jQuery.ajax( "non-existing", {
  1251. context: context,
  1252. beforeSend: function() {
  1253. ok( this === context, "context was not deep extended" );
  1254. return false;
  1255. }
  1256. });
  1257. success = true;
  1258. } catch ( e ) {
  1259. console.log( e );
  1260. }
  1261. ok( success, "context with circular reference did not generate an exception" );
  1262. });
  1263. jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) {
  1264. function request( url, test ) {
  1265. return {
  1266. create: function() {
  1267. return jQuery.ajax( inSetting ? { url: url } : url );
  1268. },
  1269. done: function() {
  1270. ok( true, ( test || url ) + " " + title );
  1271. }
  1272. };
  1273. }
  1274. ajaxTest( "#10093 - jQuery.ajax() - falsy url " + title, 4, [
  1275. request( "", "empty string" ),
  1276. request( false ),
  1277. request( null ),
  1278. request( undefined )
  1279. ]);
  1280. });
  1281. ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, {
  1282. url: url("data/errorWithJSON.php"),
  1283. dataFilter: function( string ) {
  1284. ok( false, "dataFilter called" );
  1285. return string;
  1286. },
  1287. error: function( jqXHR ) {
  1288. strictEqual( jqXHR.responseText, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" );
  1289. deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" );
  1290. }
  1291. });
  1292. ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, {
  1293. url: url("data/1x1.jpg"),
  1294. success: function( data ) {
  1295. ok( data === undefined || /JFIF/.test( data ), "success callback reached" );
  1296. }
  1297. });
  1298. asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function() {
  1299. var onerror = window.onerror;
  1300. window.onerror = function() {
  1301. ok( true, "Exception thrown" );
  1302. window.onerror = onerror;
  1303. start();
  1304. };
  1305. jQuery.ajax({
  1306. url: "data/badjson.js",
  1307. dataType: "script",
  1308. throws: true,
  1309. // Global events get confused by the exception
  1310. global: false,
  1311. success: function() {
  1312. ok( false, "Success." );
  1313. },
  1314. error: function() {
  1315. ok( false, "Error." );
  1316. }
  1317. });
  1318. });
  1319. jQuery.each( [ "method", "type" ], function( _, globalOption ) {
  1320. function request( option ) {
  1321. var options = {
  1322. url: url("data/echoData.php"),
  1323. data: "hello",
  1324. success: function( msg ) {
  1325. strictEqual( msg, "hello", "Check for POST (no override)" );
  1326. }
  1327. };
  1328. if ( option ) {
  1329. options[ option ] = "GET";
  1330. options.success = function( msg ) {
  1331. strictEqual( msg, "", "Check for no POST (overriding with " + option + ")" );
  1332. };
  1333. }
  1334. return options;
  1335. }
  1336. ajaxTest( "#12004 - jQuery.ajax() - method is an alias of type - " + globalOption + " set globally", 3, {
  1337. setup: function() {
  1338. var options = {};
  1339. options[ globalOption ] = "POST";
  1340. jQuery.ajaxSetup( options );
  1341. },
  1342. requests: [
  1343. request("type"),
  1344. request("method"),
  1345. request()
  1346. ]
  1347. });
  1348. });
  1349. ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, {
  1350. url: "data/dashboard.xml",
  1351. dataType: "xml",
  1352. success: function( ajaxXML ) {
  1353. var parsedXML = jQuery( jQuery.parseXML("<tab title=\"Added\">blibli</tab>") ).find("tab");
  1354. ajaxXML = jQuery( ajaxXML );
  1355. try {
  1356. ajaxXML.find("infowindowtab").append( parsedXML );
  1357. } catch( e ) {
  1358. strictEqual( e, undefined, "error" );
  1359. return;
  1360. }
  1361. strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" );
  1362. }
  1363. });
  1364. ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, {
  1365. url: "data/nocontent.php",
  1366. dataType: "testing",
  1367. converters: {
  1368. "* testing": function() {
  1369. throw "converter was called";
  1370. }
  1371. },
  1372. success: function( data, status, jqXHR ) {
  1373. strictEqual( jqXHR.status, 204, "status code is 204" );
  1374. strictEqual( status, "nocontent", "status text is 'nocontent'" );
  1375. strictEqual( data, undefined, "data is undefined" );
  1376. },
  1377. error: function( _, status, error ) {
  1378. ok( false, "error" );
  1379. strictEqual( status, "parsererror", "Parser Error" );
  1380. strictEqual( error, "converter was called", "Converter was called" );
  1381. }
  1382. });
  1383. ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, {
  1384. url: url("data/with_fries.xml"),
  1385. dataType: "xml",
  1386. success: function( resp, _, jqXHR ) {
  1387. notStrictEqual( resp, undefined, "XML document exists" );
  1388. ok( "responseXML" in jqXHR, "jqXHR.responseXML exists" );
  1389. strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" );
  1390. }
  1391. });
  1392. ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, {
  1393. url: "data/json.php",
  1394. method: "HEAD",
  1395. data: {
  1396. header: "yes"
  1397. },
  1398. converters: {
  1399. "text json": function() {
  1400. throw "converter was called";
  1401. }
  1402. },
  1403. success: function( data, status ) {
  1404. ok( true, "success" );
  1405. strictEqual( status, "nocontent", "data is undefined" );
  1406. strictEqual( data, undefined, "data is undefined" );
  1407. },
  1408. error: function( _, status, error ) {
  1409. ok( false, "error" );
  1410. strictEqual( status, "parsererror", "Parser Error" );
  1411. strictEqual( error, "converter was called", "Converter was called" );
  1412. }
  1413. } );
  1414. //----------- jQuery.ajaxPrefilter()
  1415. ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, {
  1416. setup: function() {
  1417. jQuery.ajaxPrefilter(function( options, _, jqXHR ) {
  1418. if ( options.abortInPrefilter ) {
  1419. jqXHR.abort();
  1420. }
  1421. });
  1422. },
  1423. abortInPrefilter: true,
  1424. error: function() {
  1425. ok( false, "error callback called" );
  1426. },
  1427. fail: function( _, reason ) {
  1428. strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" );
  1429. }
  1430. });
  1431. //----------- jQuery.ajaxSetup()
  1432. asyncTest( "jQuery.ajaxSetup()", 1, function() {
  1433. jQuery.ajaxSetup({
  1434. url: url("data/name.php?name=foo"),
  1435. success: function( msg ) {
  1436. strictEqual( msg, "bar", "Check for GET" );
  1437. start();
  1438. }
  1439. });
  1440. jQuery.ajax();
  1441. });
  1442. asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function() {
  1443. var passed = 0,
  1444. pass = function() {
  1445. ok( passed++ < 2, "Error callback executed" );
  1446. if ( passed === 2 ) {
  1447. jQuery( document ).off("ajaxError.setupTest");
  1448. start();
  1449. }
  1450. },
  1451. fail = function( a, b ) {
  1452. ok( false, "Check for timeout failed " + a + " " + b );
  1453. start();
  1454. };
  1455. jQuery( document ).on( "ajaxError.setupTest", pass );
  1456. jQuery.ajaxSetup({
  1457. timeout: 1000
  1458. });
  1459. jQuery.ajax({
  1460. type: "GET",
  1461. url: url("data/name.php?wait=5"),
  1462. error: pass,
  1463. success: fail
  1464. });
  1465. });
  1466. asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function() {
  1467. jQuery.ajaxSetup({
  1468. timeout: 50
  1469. });
  1470. jQuery.ajax({
  1471. type: "GET",
  1472. timeout: 15000,
  1473. url: url("data/name.php?wait=1"),
  1474. error: function() {
  1475. ok( false, "Check for local timeout failed" );
  1476. start();
  1477. },
  1478. success: function() {
  1479. ok( true, "Check for local timeout" );
  1480. start();
  1481. }
  1482. });
  1483. });
  1484. //----------- jQuery.domManip()
  1485. test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", 1, function() {
  1486. jQuery.ajaxSetup({
  1487. type: "POST"
  1488. });
  1489. jQuery( document ).on( "ajaxStart ajaxStop", function() {
  1490. ok( false, "Global event triggered" );
  1491. });
  1492. jQuery("#qunit-fixture").append("<script src='data/evalScript.php'></script>");
  1493. jQuery( document ).off("ajaxStart ajaxStop");
  1494. });
  1495. asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() {
  1496. jQuery("#qunit-fixture").load( "data/cleanScript.html", start );
  1497. });
  1498. //----------- jQuery.get()
  1499. asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function() {
  1500. jQuery.get( url("data/dashboard.xml"), function( xml ) {
  1501. var content = [];
  1502. jQuery( "tab", xml ).each(function() {
  1503. content.push( jQuery( this ).text() );
  1504. });
  1505. strictEqual( content[ 0 ], "blabla", "Check first tab" );
  1506. strictEqual( content[ 1 ], "blublu", "Check second tab" );
  1507. start();
  1508. });
  1509. });
  1510. asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function() {
  1511. jQuery.ajaxSetup({
  1512. data: "helloworld"
  1513. });
  1514. jQuery.get( url("data/echoQuery.php"), function( data ) {
  1515. ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" );
  1516. start();
  1517. });
  1518. });
  1519. //----------- jQuery.getJSON()
  1520. asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function() {
  1521. jQuery.getJSON(
  1522. url("data/json.php"),
  1523. {
  1524. "json": "array"
  1525. },
  1526. function( json ) {
  1527. ok( json.length >= 2, "Check length" );
  1528. strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
  1529. strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
  1530. strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
  1531. strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
  1532. start();
  1533. }
  1534. );
  1535. });
  1536. asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function() {
  1537. jQuery.getJSON( url("data/json.php"), function( json ) {
  1538. if ( json && json["data"] ) {
  1539. strictEqual( json["data"]["lang"], "en", "Check JSON: lang" );
  1540. strictEqual( json["data"].length, 25, "Check JSON: length" );
  1541. start();
  1542. }
  1543. });
  1544. });
  1545. asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function() {
  1546. jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) {
  1547. strictEqual( json.data.lang, "en", "Check JSON: lang" );
  1548. strictEqual( json.data.length, 25, "Check JSON: length" );
  1549. start();
  1550. });
  1551. });
  1552. //----------- jQuery.getScript()
  1553. asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() {
  1554. Globals.register("testBar");
  1555. jQuery.getScript( url("data/test.js"), function() {
  1556. strictEqual( window["testBar"], "bar", "Check if script was evaluated" );
  1557. start();
  1558. });
  1559. });
  1560. asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() {
  1561. Globals.register("testBar");
  1562. jQuery.getScript( url("data/test.js") ).done( start );
  1563. });
  1564. asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function() {
  1565. Globals.register("testBar");
  1566. jQuery.getScript( url("data/test.js"), function( data, _, jqXHR ) {
  1567. strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" );
  1568. start();
  1569. });
  1570. });
  1571. //----------- jQuery.fn.load()
  1572. // check if load can be called with only url
  1573. asyncTest( "jQuery.fn.load( String )", 2, function() {
  1574. jQuery.ajaxSetup({
  1575. beforeSend: function() {
  1576. strictEqual( this.type, "GET", "no data means GET request" );
  1577. }
  1578. });
  1579. jQuery("#first").load( "data/name.html", start );
  1580. });
  1581. asyncTest( "jQuery.fn.load() - 404 error callbacks", 6, function() {
  1582. addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError")();
  1583. jQuery( document ).ajaxStop( start );
  1584. jQuery("<div/>").load( "data/404.html", function() {
  1585. ok( true, "complete" );
  1586. });
  1587. });
  1588. // check if load can be called with url and null data
  1589. asyncTest( "jQuery.fn.load( String, null )", 2, function() {
  1590. jQuery.ajaxSetup({
  1591. beforeSend: function() {
  1592. strictEqual( this.type, "GET", "no data means GET request" );
  1593. }
  1594. });
  1595. jQuery("#first").load( "data/name.html", null, start );
  1596. });
  1597. // check if load can be called with url and undefined data
  1598. asyncTest( "jQuery.fn.load( String, undefined )", 2, function() {
  1599. jQuery.ajaxSetup({
  1600. beforeSend: function() {
  1601. strictEqual( this.type, "GET", "no data means GET request" );
  1602. }
  1603. });
  1604. jQuery("#first").load( "data/name.html", undefined, start );
  1605. });
  1606. // check if load can be called with only url
  1607. asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function() {
  1608. jQuery("#first").load( "data/test3.html div.user", function() {
  1609. strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" );
  1610. start();
  1611. });
  1612. });
  1613. asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() {
  1614. jQuery("#first").load( url("data/name.html"), function() {
  1615. ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );
  1616. start();
  1617. });
  1618. });
  1619. asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function() {
  1620. var verifyEvaluation = function() {
  1621. strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" );
  1622. strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
  1623. start();
  1624. };
  1625. Globals.register("testFoo");
  1626. Globals.register("testBar");
  1627. jQuery("#first").load( url("data/test.html"), function() {
  1628. ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" );
  1629. strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" );
  1630. strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
  1631. setTimeout( verifyEvaluation, 600 );
  1632. });
  1633. });
  1634. asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function() {
  1635. Globals.register("testFoo");
  1636. jQuery("#first").load( url("data/test2.html"), function() {
  1637. strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
  1638. strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
  1639. start();
  1640. });
  1641. });
  1642. asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function() {
  1643. jQuery.ajaxSetup({
  1644. dataFilter: function() {
  1645. return "Hello World";
  1646. }
  1647. });
  1648. jQuery("<div/>").load( url("data/name.html"), function( responseText ) {
  1649. strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
  1650. strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
  1651. start();
  1652. });
  1653. });
  1654. asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function() {
  1655. jQuery("<div />").load( url("data/params_html.php"), {
  1656. "foo": 3,
  1657. "bar": "ok"
  1658. }, function() {
  1659. var $post = jQuery( this ).find("#post");
  1660. strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" );
  1661. strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" );
  1662. start();
  1663. });
  1664. });
  1665. asyncTest( "jQuery.fn.load( String, String, Function )", 2, function() {
  1666. jQuery("<div />").load( url("data/params_html.php"), "foo=3&bar=ok", function() {
  1667. var $get = jQuery( this ).find("#get");
  1668. strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" );
  1669. strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" );
  1670. start();
  1671. });
  1672. });
  1673. asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() {
  1674. var completeArgs = {};
  1675. jQuery.ajaxSetup({
  1676. success: function( _, status, jqXHR ) {
  1677. completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
  1678. },
  1679. error: function( jqXHR, status ) {
  1680. completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
  1681. }
  1682. });
  1683. jQuery.when.apply(
  1684. jQuery,
  1685. jQuery.map([
  1686. {
  1687. type: "success",
  1688. url: "data/echoQuery.php?arg=pop"
  1689. },
  1690. {
  1691. type: "error",
  1692. url: "data/404.php"
  1693. }
  1694. ],
  1695. function( options ) {
  1696. return jQuery.Deferred(function( defer ) {
  1697. jQuery("#foo").load( options.url, function() {
  1698. var args = arguments;
  1699. strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" );
  1700. jQuery.each( completeArgs[ options.url ], function( i, value ) {
  1701. strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" );
  1702. });
  1703. defer.resolve();
  1704. });
  1705. });
  1706. })
  1707. ).always( start );
  1708. });
  1709. asyncTest( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function() {
  1710. jQuery.ajaxSetup({
  1711. dataType: "json"
  1712. });
  1713. jQuery( document ).ajaxComplete(function( e, xml, s ) {
  1714. strictEqual( s.dataType, "html", "Verify the load() dataType was html" );
  1715. jQuery( document ).off("ajaxComplete");
  1716. start();
  1717. });
  1718. jQuery("#first").load("data/test3.html");
  1719. });
  1720. asyncTest( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function() {
  1721. var data = {
  1722. "baz": 1
  1723. };
  1724. jQuery.ajaxSetup({
  1725. data: {
  1726. "foo": "bar"
  1727. }
  1728. });
  1729. jQuery("#foo").load( "data/echoQuery.php", data );
  1730. jQuery( document ).ajaxComplete(function( event, jqXHR, options ) {
  1731. ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" );
  1732. start();
  1733. });
  1734. });
  1735. //----------- jQuery.post()
  1736. asyncTest( "jQuery.post() - data", 3, function() {
  1737. jQuery.when(
  1738. jQuery.post(
  1739. url("data/name.php"),
  1740. {
  1741. xml: "5-2",
  1742. length: 3
  1743. },
  1744. function( xml ) {
  1745. jQuery( "math", xml ).each(function() {
  1746. strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
  1747. strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
  1748. });
  1749. }
  1750. ),
  1751. jQuery.ajax({
  1752. url: url("data/echoData.php"),
  1753. type: "POST",
  1754. data: {
  1755. "test": {
  1756. "length": 7,
  1757. "foo": "bar"
  1758. }
  1759. },
  1760. success: function( data ) {
  1761. strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" );
  1762. }
  1763. })
  1764. ).always( start );
  1765. });
  1766. asyncTest( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function() {
  1767. jQuery.when(
  1768. jQuery.post(
  1769. url("data/name.php"),
  1770. {
  1771. "xml": "5-2"
  1772. },
  1773. function( xml ) {
  1774. jQuery( "math", xml ).each(function() {
  1775. strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
  1776. strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
  1777. });
  1778. }
  1779. ),
  1780. jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) {
  1781. jQuery( "math", xml ).each(function() {
  1782. strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
  1783. strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
  1784. });
  1785. })
  1786. ).always( start );
  1787. });
  1788. //----------- jQuery.active
  1789. test( "jQuery.active", 1, function() {
  1790. ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );
  1791. });
  1792. })();