3 // Safari 3 randomly crashes when running these tests,
4 // but only in the full suite - you can run just the Ajax
5 // tests and they'll pass
6 //if ( !jQuery.browser.safari ) {
10 test("jQuery.ajax() - success callbacks", function() {
13 jQuery.ajaxSetup({ timeout: 0 });
17 setTimeout(function(){
18 jQuery('#foo').ajaxStart(function(){
19 ok( true, "ajaxStart" );
20 }).ajaxStop(function(){
21 ok( true, "ajaxStop" );
23 }).ajaxSend(function(){
24 ok( true, "ajaxSend" );
25 }).ajaxComplete(function(){
26 ok( true, "ajaxComplete" );
27 }).ajaxError(function(){
28 ok( false, "ajaxError" );
29 }).ajaxSuccess(function(){
30 ok( true, "ajaxSuccess" );
34 url: url("data/name.html"),
35 beforeSend: function(){ ok(true, "beforeSend"); },
36 success: function(){ ok(true, "success"); },
37 error: function(){ ok(false, "error"); },
38 complete: function(){ ok(true, "complete"); }
43 test("jQuery.ajax() - error callbacks", function() {
47 jQuery('#foo').ajaxStart(function(){
48 ok( true, "ajaxStart" );
49 }).ajaxStop(function(){
50 ok( true, "ajaxStop" );
52 }).ajaxSend(function(){
53 ok( true, "ajaxSend" );
54 }).ajaxComplete(function(){
55 ok( true, "ajaxComplete" );
56 }).ajaxError(function(){
57 ok( true, "ajaxError" );
58 }).ajaxSuccess(function(){
59 ok( false, "ajaxSuccess" );
62 jQuery.ajaxSetup({ timeout: 500 });
65 url: url("data/name.php?wait=5"),
66 beforeSend: function(){ ok(true, "beforeSend"); },
67 success: function(){ ok(false, "success"); },
68 error: function(){ ok(true, "error"); },
69 complete: function(){ ok(true, "complete"); }
73 test("Ajax events with context", function() {
77 var context = document.createElement("div");
80 equals( this, context, e.type );
84 equals( this, context, "context is preserved on callback" );
87 jQuery('#foo').add(context)
94 url: url("data/name.html"),
100 setTimeout(proceed, 300);
106 jQuery('#foo').add(context).unbind();
111 test("jQuery.ajax() - disabled globals", function() {
115 jQuery('#foo').ajaxStart(function(){
116 ok( false, "ajaxStart" );
117 }).ajaxStop(function(){
118 ok( false, "ajaxStop" );
119 }).ajaxSend(function(){
120 ok( false, "ajaxSend" );
121 }).ajaxComplete(function(){
122 ok( false, "ajaxComplete" );
123 }).ajaxError(function(){
124 ok( false, "ajaxError" );
125 }).ajaxSuccess(function(){
126 ok( false, "ajaxSuccess" );
131 url: url("data/name.html"),
132 beforeSend: function(){ ok(true, "beforeSend"); },
133 success: function(){ ok(true, "success"); },
134 error: function(){ ok(false, "error"); },
135 complete: function(){
136 ok(true, "complete");
137 setTimeout(function(){ start(); }, 13);
142 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
146 url: url("data/with_fries.xml"),
148 success: function(resp) {
149 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
150 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
151 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
157 test("jQuery.ajax - beforeSend", function() {
163 jQuery.ajaxSetup({ timeout: 0 });
166 url: url("data/name.html"),
167 beforeSend: function(xml) {
170 success: function(data) {
171 ok( check, "check beforeSend was executed" );
177 test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
179 var request = jQuery.ajax({
180 url: url("data/name.html"),
181 beforeSend: function() {
182 ok( true, "beforeSend got called, canceling" );
185 success: function() {
186 ok( false, "request didn't get canceled" );
188 complete: function() {
189 ok( false, "request didn't get canceled" );
192 ok( false, "request didn't get canceled" );
195 ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
198 window.foobar = null;
199 window.testFoo = undefined;
201 test("jQuery.ajax - dataType html", function() {
205 var verifyEvaluation = function() {
206 equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
207 equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
214 url: url("data/test.html"),
215 success: function(data) {
216 jQuery("#ap").html(data);
217 ok( data.match(/^html text/), 'Check content for datatype html' );
218 setTimeout(verifyEvaluation, 600);
223 test("serialize()", function() {
226 // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
227 jQuery("#search").after(
228 '<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+
229 '<input type="number" id="html5number" name="number" value="43" />'
232 equals( jQuery('#form').serialize(),
233 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2",
234 'Check form serialization as query string');
236 equals( jQuery('#form :input').serialize(),
237 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2",
238 'Check input serialization as query string');
240 equals( jQuery('#testForm').serialize(),
241 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
242 'Check form serialization as query string');
244 equals( jQuery('#testForm :input').serialize(),
245 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
246 'Check input serialization as query string');
248 equals( jQuery('#form, #testForm').serialize(),
249 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
250 'Multiple form serialization as query string');
252 /* Temporarily disabled. Opera 10 has problems with form serialization.
253 equals( jQuery('#form, #testForm :input').serialize(),
254 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
255 'Mixed form/input serialization as query string');
257 jQuery("#html5email, #html5number").remove();
260 test("jQuery.param()", function() {
263 equals( jQuery.param.traditional, undefined, "traditional flag, undefined by default" );
265 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
266 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
268 params = {someName: [1, 2, 3], regularThing: "blah" };
269 equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" );
271 params = {foo: ['a', 'b', 'c']};
272 equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
274 params = {foo: ["baz", 42, "All your base are belong to us"] };
275 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
277 params = {foo: { bar: 'baz', beep: 42, quux: 'All your base are belong to us' } };
278 equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
280 params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
281 equals( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure" );
283 params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
284 equals( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
286 jQuery.param.traditional = true;
288 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
289 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
291 params = {someName: [1, 2, 3], regularThing: "blah" };
292 equals( jQuery.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" );
294 params = {foo: ['a', 'b', 'c']};
295 equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
297 params = {"foo[]":["baz", 42, "All your base are belong to us"]};
298 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
300 params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
301 equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
303 params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
304 equals( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure" );
306 params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
307 equals( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
311 test("synchronous request", function() {
313 ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" );
316 test("synchronous request with callbacks", function() {
319 jQuery.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } });
320 ok( /^{ "data"/.test( result ), "check returned text" );
323 test("pass-through request object", function() {
327 var target = "data/name.html";
328 var successCount = 0;
331 var success = function() {
334 jQuery("#foo").ajaxError(function (e, xml, s, ex) {
336 errorEx += ": " + xml.status;
338 jQuery("#foo").one('ajaxStop', function () {
339 equals(successCount, 5, "Check all ajax calls successful");
340 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
341 jQuery("#foo").unbind('ajaxError');
346 ok( jQuery.get(url(target), success), "get" );
347 ok( jQuery.post(url(target), success), "post" );
348 ok( jQuery.getScript(url("data/test.js"), success), "script" );
349 ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
350 ok( jQuery.ajax({url: url(target), success: success}), "generic" );
353 test("ajax cache", function () {
360 jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
361 var re = /_=(.*?)(&|$)/g;
363 for (var i = 0; i < 6; i++) {
364 var ret = re.exec(s.url);
370 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
371 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
376 ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
377 ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
378 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
379 ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
380 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
381 ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
386 * The assertions expect that the passed-in object will be modified,
387 * which shouldn't be the case. Fixes #5439.
388 test("global ajaxSettings", function() {
391 var tmp = jQuery.extend({}, jQuery.ajaxSettings);
392 var orig = { url: "data/with_fries.xml" };
395 jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
397 t = jQuery.extend({}, orig);
400 ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
402 t = jQuery.extend({}, orig);
403 t.data = { zoo: 'a', ping: 'b' };
405 ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" );
407 jQuery.ajaxSettings = tmp;
411 test("load(String)", function() {
413 stop(); // check if load can be called with only url
414 jQuery('#first').load("data/name.html", start);
417 test("load('url selector')", function() {
419 stop(); // check if load can be called with only url
420 jQuery('#first').load("data/test3.html div.user", function(){
421 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
426 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
429 jQuery.ajaxSetup({ dataType: "json" });
430 jQuery("#first").ajaxComplete(function (e, xml, s) {
431 equals( s.dataType, "html", "Verify the load() dataType was html" );
432 jQuery("#first").unbind("ajaxComplete");
433 jQuery.ajaxSetup({ dataType: "" });
436 jQuery('#first').load("data/test3.html");
439 test("load(String, Function) - simple: inject text into DOM", function() {
442 jQuery('#first').load(url("data/name.html"), function() {
443 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
448 test("load(String, Function) - check scripts", function() {
452 var verifyEvaluation = function() {
453 equals( foobar, "bar", 'Check if script src was evaluated after load' );
454 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
458 jQuery('#first').load(url('data/test.html'), function() {
459 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
460 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
461 equals( testFoo, "foo", 'Check if script was evaluated after load' );
462 setTimeout(verifyEvaluation, 600);
466 test("load(String, Function) - check file with only a script tag", function() {
470 jQuery('#first').load(url('data/test2.html'), function() {
471 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
472 equals( testFoo, "foo", 'Check if script was evaluated after load' );
478 test("load(String, Object, Function)", function() {
482 jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
483 var $post = jQuery(this).find('#post');
484 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
485 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
490 test("load(String, String, Function)", function() {
494 jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
495 var $get = jQuery(this).find('#get');
496 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
497 equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly');
502 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
505 jQuery.get(url('data/dashboard.xml'), function(xml) {
507 jQuery('tab', xml).each(function() {
508 content.push(jQuery(this).text());
510 equals( content[0], 'blabla', 'Check first tab');
511 equals( content[1], 'blublu', 'Check second tab');
516 test("jQuery.getScript(String, Function) - with callback", function() {
519 jQuery.getScript(url("data/test.js"), function() {
520 equals( foobar, "bar", 'Check if script was evaluated' );
521 setTimeout(start, 100);
525 test("jQuery.getScript(String, Function) - no callback", function() {
528 jQuery.getScript(url("data/test.js"), function(){
533 test("jQuery.ajax() - JSONP, Local", function() {
537 function plus(){ if ( ++count == 8 ) start(); }
542 url: "data/jsonp.php",
544 success: function(data){
545 ok( data.data, "JSON results returned (GET, no callback)" );
548 error: function(data){
549 ok( false, "Ajax error JSON (GET, no callback)" );
555 url: "data/jsonp.php?callback=?",
557 success: function(data){
558 ok( data.data, "JSON results returned (GET, url callback)" );
561 error: function(data){
562 ok( false, "Ajax error JSON (GET, url callback)" );
568 url: "data/jsonp.php",
571 success: function(data){
572 ok( data.data, "JSON results returned (GET, data callback)" );
575 error: function(data){
576 ok( false, "Ajax error JSON (GET, data callback)" );
582 url: "data/jsonp.php",
585 success: function(data){
586 ok( data.data, "JSON results returned (GET, data obj callback)" );
589 error: function(data){
590 ok( false, "Ajax error JSON (GET, data obj callback)" );
596 url: "data/jsonp.php",
598 jsonpCallback: "jsonpResults",
599 success: function(data){
600 ok( data.data, "JSON results returned (GET, custom callback name)" );
603 error: function(data){
604 ok( false, "Ajax error JSON (GET, custom callback name)" );
611 url: "data/jsonp.php",
613 success: function(data){
614 ok( data.data, "JSON results returned (POST, no callback)" );
617 error: function(data){
618 ok( false, "Ajax error JSON (GET, data obj callback)" );
625 url: "data/jsonp.php",
628 success: function(data){
629 ok( data.data, "JSON results returned (POST, data callback)" );
632 error: function(data){
633 ok( false, "Ajax error JSON (POST, data callback)" );
640 url: "data/jsonp.php",
643 success: function(data){
644 ok( data.data, "JSON results returned (POST, data obj callback)" );
647 error: function(data){
648 ok( false, "Ajax error JSON (POST, data obj callback)" );
654 test("JSONP - Custom JSONP Callback", function() {
658 window.jsonpResults = function(data) {
659 ok( data.data, "JSON results returned (GET, custom callback function)" );
664 url: "data/jsonp.php",
666 jsonpCallback: "jsonpResults"
670 test("jQuery.ajax() - JSONP, Remote", function() {
674 function plus(){ if ( ++count == 4 ) start(); }
676 var base = window.location.href.replace(/\?.*$/, "");
681 url: base + "data/jsonp.php",
683 success: function(data){
684 ok( data.data, "JSON results returned (GET, no callback)" );
687 error: function(data){
688 ok( false, "Ajax error JSON (GET, no callback)" );
694 url: base + "data/jsonp.php?callback=?",
696 success: function(data){
697 ok( data.data, "JSON results returned (GET, url callback)" );
700 error: function(data){
701 ok( false, "Ajax error JSON (GET, url callback)" );
707 url: base + "data/jsonp.php",
710 success: function(data){
711 ok( data.data, "JSON results returned (GET, data callback)" );
714 error: function(data){
715 ok( false, "Ajax error JSON (GET, data callback)" );
721 url: base + "data/jsonp.php",
724 success: function(data){
725 ok( data.data, "JSON results returned (GET, data obj callback)" );
728 error: function(data){
729 ok( false, "Ajax error JSON (GET, data obj callback)" );
735 test("jQuery.ajax() - script, Remote", function() {
738 var base = window.location.href.replace(/\?.*$/, "");
743 url: base + "data/test.js",
745 success: function(data){
746 ok( foobar, "Script results returned (GET, no callback)" );
752 test("jQuery.ajax() - script, Remote with POST", function() {
755 var base = window.location.href.replace(/\?.*$/, "");
760 url: base + "data/test.js",
763 success: function(data, status){
764 ok( foobar, "Script results returned (POST, no callback)" );
765 equals( status, "success", "Script results returned (POST, no callback)" );
768 error: function(xhr) {
769 ok( false, "ajax error, status code: " + xhr.status );
775 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
778 var base = window.location.href.replace(/\?.*$/, "");
779 base = base.replace(/^.*?\/\//, "//");
784 url: base + "data/test.js",
786 success: function(data){
787 ok( foobar, "Script results returned (GET, no callback)" );
793 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
796 jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
797 ok( json.length >= 2, "Check length");
798 equals( json[0].name, 'John', 'Check JSON: first, name' );
799 equals( json[0].age, 21, 'Check JSON: first, age' );
800 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
801 equals( json[1].age, 25, 'Check JSON: second, age' );
806 test("jQuery.getJSON(String, Function) - JSON object", function() {
809 jQuery.getJSON(url("data/json.php"), function(json) {
810 if (json && json.data) {
811 equals( json.data.lang, 'en', 'Check JSON: lang' );
812 equals( json.data.length, 25, 'Check JSON: length' );
818 test("jQuery.getJSON - Using Native JSON", function() {
821 var old = window.JSON;
823 parse: function(str){
824 ok( true, "Verifying that parse method was run" );
830 jQuery.getJSON(url("data/json.php"), function(json) {
832 equals( json, true, "Verifying return value" );
837 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
840 var base = window.location.href.replace(/\?.*$/, "");
843 jQuery.getJSON(url(base + "data/json.php"), function(json) {
844 equals( json.data.lang, 'en', 'Check JSON: lang' );
845 equals( json.data.length, 25, 'Check JSON: length' );
850 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
855 jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
856 jQuery('math', xml).each(function() {
857 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
858 equals( jQuery('result', this).text(), '3', 'Check for XML' );
860 if ( ++done === 2 ) start();
863 jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
864 jQuery('math', xml).each(function() {
865 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
866 equals( jQuery('result', this).text(), '3', 'Check for XML' );
868 if ( ++done === 2 ) start();
872 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
877 jQuery.ajaxSetup({timeout: 1000});
879 var pass = function() {
882 ok( true, 'Check local and global callbacks after timeout' );
883 jQuery('#main').unbind("ajaxError");
888 var fail = function(a,b,c) {
889 ok( false, 'Check for timeout failed ' + a + ' ' + b );
893 jQuery('#main').ajaxError(pass);
897 url: url("data/name.php?wait=5"),
903 jQuery.ajaxSetup({timeout: 0});
906 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
908 jQuery.ajaxSetup({timeout: 50});
913 url: url("data/name.php?wait=1"),
915 ok( false, 'Check for local timeout failed' );
918 success: function() {
919 ok( true, 'Check for local timeout' );
925 jQuery.ajaxSetup({timeout: 0});
928 test("jQuery.ajax - simple get", function() {
933 url: url("data/name.php?name=foo"),
934 success: function(msg){
935 equals( msg, 'bar', 'Check for GET' );
941 test("jQuery.ajax - simple post", function() {
946 url: url("data/name.php"),
948 success: function(msg){
949 equals( msg, 'pan', 'Check for POST' );
955 test("ajaxSetup()", function() {
959 url: url("data/name.php?name=foo"),
960 success: function(msg){
961 equals( msg, 'bar', 'Check for GET' );
969 test("custom timeout does not set error message when timeout occurs, see #970", function() {
972 url: "data/name.php?wait=1",
974 error: function(request, status) {
975 ok( status != null, "status shouldn't be null in error handler" );
976 equals( "timeout", status );
983 test("data option: evaluate function values (#2806)", function() {
986 url: "data/echoQuery.php",
992 success: function(result) {
993 equals( result, "key=value" );
999 test("jQuery.ajax - If-Modified-Since support", function() {
1004 var url = "data/if_modified_since.php?ts=" + new Date();
1009 success: function(data, status) {
1010 equals(status, "success");
1015 success: function(data, status) {
1016 if ( data === "FAIL" ) {
1017 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1018 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1020 equals(status, "notmodified");
1021 ok(data == null, "response body should be empty")
1030 test("jQuery.ajax - Etag support", function() {
1035 var url = "data/etag.php?ts=" + new Date();
1040 success: function(data, status) {
1041 equals(status, "success");
1046 success: function(data, status) {
1047 if ( data === "FAIL" ) {
1048 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1049 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1051 equals(status, "notmodified");
1052 ok(data == null, "response body should be empty")