3 // Safari 3 randomly crashes when running these tests,
4 // but only in the full suite - you can run just the Ajax
5 // tests and they'll pass
6 //if ( !jQuery.browser.safari ) {
10 test("jQuery.ajax() - success callbacks", function() {
13 jQuery.ajaxSetup({ timeout: 0 });
17 jQuery('#foo').ajaxStart(function(){
18 ok( true, "ajaxStart" );
19 }).ajaxStop(function(){
20 ok( true, "ajaxStop" );
22 }).ajaxSend(function(){
23 ok( true, "ajaxSend" );
24 }).ajaxComplete(function(){
25 ok( true, "ajaxComplete" );
26 }).ajaxError(function(){
27 ok( false, "ajaxError" );
28 }).ajaxSuccess(function(){
29 ok( true, "ajaxSuccess" );
33 url: url("data/name.html"),
34 beforeSend: function(){ ok(true, "beforeSend"); },
35 success: function(){ ok(true, "success"); },
36 error: function(){ ok(false, "error"); },
37 complete: function(){ ok(true, "complete"); }
41 test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
44 jQuery.ajaxSetup({ timeout: 0 });
48 setTimeout(function(){
49 jQuery('#foo').ajaxStart(function(){
50 ok( true, "ajaxStart" );
51 }).ajaxStop(function(){
52 ok( true, "ajaxStop" );
54 }).ajaxSend(function(){
55 ok( true, "ajaxSend" );
56 }).ajaxComplete(function(){
57 ok( true, "ajaxComplete" );
58 }).ajaxError(function(){
59 ok( false, "ajaxError" );
60 }).ajaxSuccess(function(){
61 ok( true, "ajaxSuccess" );
64 jQuery.ajax( url("data/name.html") , {
65 beforeSend: function(){ ok(true, "beforeSend"); },
66 success: function(){ ok(true, "success"); },
67 error: function(){ ok(false, "error"); },
68 complete: function(){ ok(true, "complete"); }
73 test("jQuery.ajax() - success/error callbacks (remote)", function() {
75 var supports = jQuery.support.cors;
77 expect( supports ? 9 : 6 );
79 jQuery.ajaxSetup({ timeout: 0 });
83 setTimeout(function(){
84 jQuery('#foo').ajaxStart(function(){
85 ok( true, "ajaxStart" );
86 }).ajaxStop(function(){
87 ok( true, "ajaxStop" );
89 }).ajaxSend(function(){
90 ok( supports , "ajaxSend" );
91 }).ajaxComplete(function(){
92 ok( true, "ajaxComplete" );
93 }).ajaxError(function(){
94 ok( ! supports, "ajaxError" );
95 }).ajaxSuccess(function(){
96 ok( supports, "ajaxSuccess" );
100 // JULIAN TODO: Get an url especially for jQuery
101 url: "http://rockstarapps.com/test.php",
103 beforeSend: function(){ ok(supports, "beforeSend"); },
104 success: function( val ){ ok(supports, "success"); ok(supports && val.length, "data received"); },
105 error: function(_ , a , b ){ ok(!supports, "error"); },
106 complete: function(){ ok(true, "complete"); }
111 test("jQuery.ajax() - success callbacks (late binding)", function() {
114 jQuery.ajaxSetup({ timeout: 0 });
118 setTimeout(function(){
119 jQuery('#foo').ajaxStart(function(){
120 ok( true, "ajaxStart" );
121 }).ajaxStop(function(){
122 ok( true, "ajaxStop" );
124 }).ajaxSend(function(){
125 ok( true, "ajaxSend" );
126 }).ajaxComplete(function(){
127 ok( true, "ajaxComplete" );
128 }).ajaxError(function(){
129 ok( false, "ajaxError" );
130 }).ajaxSuccess(function(){
131 ok( true, "ajaxSuccess" );
135 url: url("data/name.html"),
136 beforeSend: function(){ ok(true, "beforeSend"); }
138 .complete(function(){ ok(true, "complete"); })
139 .success(function(){ ok(true, "success"); })
140 .error(function(){ ok(false, "error"); });
144 test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
147 jQuery.ajaxSetup({ timeout: 0 });
151 setTimeout(function(){
152 jQuery('#foo').ajaxStart(function(){
153 ok( true, "ajaxStart" );
154 }).ajaxStop(function(){
155 ok( true, "ajaxStop" );
156 }).ajaxSend(function(){
157 ok( true, "ajaxSend" );
158 }).ajaxComplete(function(){
159 ok( true, "ajaxComplete" );
160 }).ajaxError(function(){
161 ok( false, "ajaxError" );
162 }).ajaxSuccess(function(){
163 ok( true, "ajaxSuccess" );
167 url: url("data/name.html"),
168 beforeSend: function(){ ok(true, "beforeSend"); },
169 complete: function(xhr) {
171 .complete(function(){ ok(true, "complete"); })
172 .success(function(){ ok(true, "success"); })
173 .error(function(){ ok(false, "error"); })
174 .complete(function(){ start(); });
180 test("jQuery.ajax() - success callbacks (very late binding)", function() {
183 jQuery.ajaxSetup({ timeout: 0 });
187 setTimeout(function(){
188 jQuery('#foo').ajaxStart(function(){
189 ok( true, "ajaxStart" );
190 }).ajaxStop(function(){
191 ok( true, "ajaxStop" );
192 }).ajaxSend(function(){
193 ok( true, "ajaxSend" );
194 }).ajaxComplete(function(){
195 ok( true, "ajaxComplete" );
196 }).ajaxError(function(){
197 ok( false, "ajaxError" );
198 }).ajaxSuccess(function(){
199 ok( true, "ajaxSuccess" );
203 url: url("data/name.html"),
204 beforeSend: function(){ ok(true, "beforeSend"); },
205 complete: function(xhr) {
206 setTimeout (function() {
208 .complete(function(){ ok(true, "complete"); })
209 .success(function(){ ok(true, "success"); })
210 .error(function(){ ok(false, "error"); })
211 .complete(function(){ start(); });
218 test("jQuery.ajax() - success callbacks (order)", function() {
221 jQuery.ajaxSetup({ timeout: 0 });
227 setTimeout(function(){
229 url: url("data/name.html"),
230 success: function( _1 , _2 , xhr ) {
231 xhr.success(function() {
232 xhr.success(function() {
239 complete: function() {
240 strictEqual(testString, "ABCDE", "Proper order");
243 }).success(function() {
245 }).success(function() {
251 test("jQuery.ajax() - error callbacks", function() {
255 jQuery('#foo').ajaxStart(function(){
256 ok( true, "ajaxStart" );
257 }).ajaxStop(function(){
258 ok( true, "ajaxStop" );
260 }).ajaxSend(function(){
261 ok( true, "ajaxSend" );
262 }).ajaxComplete(function(){
263 ok( true, "ajaxComplete" );
264 }).ajaxError(function(){
265 ok( true, "ajaxError" );
266 }).ajaxSuccess(function(){
267 ok( false, "ajaxSuccess" );
270 jQuery.ajaxSetup({ timeout: 500 });
273 url: url("data/name.php?wait=5"),
274 beforeSend: function(){ ok(true, "beforeSend"); },
275 success: function(){ ok(false, "success"); },
276 error: function(){ ok(true, "error"); },
277 complete: function(){ ok(true, "complete"); }
281 test(".ajax() - headers" , function() {
283 // No multiple line headers in IE
284 expect( jQuery.browser.msie ? 3 : 5 );
288 var requestHeaders = {
290 "Something-Else": "other value",
291 Other: "something else"
297 for( i in requestHeaders ) {
298 list.push( i.toLowerCase() );
301 list = list.join( "_" );
303 jQuery.ajax(url("data/headers.request.php?keys="+list), {
304 headers: requestHeaders,
305 success: function( data ) {
307 for ( i in requestHeaders ) {
308 tmp.push( i.toLowerCase() , ": " , requestHeaders[ i ] , "\n" );
310 tmp = tmp.join( "" );
312 equals( data , tmp , "Headers were sent" );
313 if ( ! --sync ) start();
318 url: url("data/headers.php"),
319 success: function( _1 , _2 , xhr ){
321 equals( xhr.getResponseHeader( "Single-Line" ) , "Hello World" , "Single line header" );
322 // No multiple line headers in IE
323 if ( ! jQuery.browser.msie ) {
324 // Each browser has its own unique way to deal with spaces after line breaks
325 // in multiple line headers, so we use regular expressions
326 ok( /^Hello\s+World$/.test( xhr.getResponseHeader( "Multiple-Line" ) ) , "Multiple line" );
327 ok( /^Hello\s+Beautiful\s+World$/.test( xhr.getResponseHeader( "Multiple-Multiple-Line" ) ) , "Multiple multiple line" );
329 if ( ! --sync ) start();
331 error: function(){ ok(false, "error"); }
336 test(".ajax() - hash", function() {
340 url: "data/name.html#foo",
341 beforeSend: function( xhr, settings ) {
342 equals(settings.url, "data/name.html", "Make sure that the URL is trimmed.");
348 url: "data/name.html?abc#foo",
349 beforeSend: function( xhr, settings ) {
350 equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
356 url: "data/name.html?abc#foo",
357 data: { "test": 123 },
358 beforeSend: function( xhr, settings ) {
359 equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed.");
365 test(".ajax() - 304", function() {
370 url: url("data/notmodified.php"),
371 success: function(){ ok(true, "304 ok"); },
372 // Do this because opera simply refuses to implement 304 handling :(
373 // A feature-driven way of detecting this would be appreciated
374 // See: http://gist.github.com/599419
375 error: function(){ ok(jQuery.browser.opera, "304 not ok "); },
376 complete: function(xhr){ start(); }
380 test(".load()) - 404 error callbacks", function() {
384 jQuery('#foo').ajaxStart(function(){
385 ok( true, "ajaxStart" );
386 }).ajaxStop(function(){
387 ok( true, "ajaxStop" );
389 }).ajaxSend(function(){
390 ok( true, "ajaxSend" );
391 }).ajaxComplete(function(){
392 ok( true, "ajaxComplete" );
393 }).ajaxError(function(){
394 ok( true, "ajaxError" );
395 }).ajaxSuccess(function(){
396 ok( false, "ajaxSuccess" );
399 jQuery("<div/>").load("data/404.html", function(){
400 ok(true, "complete");
404 test("jQuery.ajax() - abort", function() {
408 jQuery('#foo').ajaxStart(function(){
409 ok( true, "ajaxStart" );
410 }).ajaxStop(function(){
411 ok( true, "ajaxStop" );
413 }).ajaxSend(function(){
414 ok( true, "ajaxSend" );
415 }).ajaxComplete(function(){
416 ok( true, "ajaxComplete" );
419 var xhr = jQuery.ajax({
420 url: url("data/name.php?wait=5"),
421 beforeSend: function(){ ok(true, "beforeSend"); },
422 complete: function(){ ok(true, "complete"); }
425 equals( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
428 equals( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
431 test("jQuery.ajax() - readyState (success)", function() {
434 jQuery.ajaxSetup({ timeout: 0 });
440 setTimeout(function(){
442 url: url("data/name.html"),
443 beforeSend: function( xhr ) {
444 xhr.onreadystatechange = function() {
445 control += xhr.readyState;
448 complete: function(){
449 setTimeout( function() {
450 equals( control , "1234" , "onreadystatechange was properly called" );
458 test("jQuery.ajax() - readyState (abort)", function() {
461 jQuery.ajaxSetup({ timeout: 0 });
467 setTimeout(function(){
469 jQuery.ajaxSetup({ timeout: 500 });
472 url: url("data/name.php?wait=5"),
473 beforeSend: function( xhr ) {
474 xhr.onreadystatechange = function() {
475 control += xhr.readyState;
478 complete: function( xhr ){
479 setTimeout( function() {
480 equals( control , "14" , "onreadystatechange was properly called" );
481 equals( xhr.readyState, 0 , "readyState is 0" );
489 test("jQuery.xhr() - reuse", function() {
492 jQuery.ajaxSetup({ timeout: 0 });
498 setTimeout(function(){
499 jQuery('#foo').ajaxStart(function(){
500 ok( true, "ajaxStart" );
501 }).ajaxStop(function(){
502 ok( true, "ajaxStop" );
504 }).ajaxSend(function(){
506 ok( true, "ajaxSend (" + number +")" );
507 }).ajaxComplete(function(){
508 ok( true, "ajaxComplete (" + number +")" );
509 }).ajaxError(function(){
510 ok( false, "ajaxError (" + number +")" );
511 }).ajaxSuccess(function(){
512 ok( true, "ajaxSuccess (" + number +")" );
516 url: url("data/name.html"),
517 beforeSend: function(){ ok(true, "beforeSend (1)"); },
518 success: function( _1 , _2 , xhr ){
519 ok(true, "success (1)");
520 xhr.complete(function() {
521 ok(true, "complete (1bis)");
523 xhr.open( "GET", url("data/name.html") );
524 xhr.success( function(){ ok(true, "beforeSend (2)"); } )
526 success: function(){ ok(true, "success (2)"); },
527 error: function(){ ok(false, "error (2)"); },
528 complete: function(){ ok(true, "complete (2)"); }
531 error: function(){ ok(false, "error (1)"); },
532 complete: function(){ ok(true, "complete (1)"); }
537 test("jQuery.xhr() - early binding", function() {
540 jQuery.ajaxSetup({ timeout: 0 });
545 .success( function(){ ok(true, "success"); } )
546 .error( function(){ ok(false, "error"); } )
547 .complete( function(){ ok(true, "complete"); start(); } )
548 .open( "GET", url("data/name.html") )
552 test("jQuery.xhr() - get native implementation", function() {
554 var xhr = jQuery.xhr(true);
556 ok( xhr.readyState !== undefined , "implements XMLHttpRequest" );
557 ok( ! jQuery.isFunction( xhr.success ) , "is not jQuery's abstraction" );
561 test("Ajax events with context", function() {
565 var context = document.createElement("div");
568 equals( this, context, e.type );
571 function callback(msg){
573 equals( this, context, "context is preserved on callback " + msg );
577 function nocallback(msg){
579 equals( typeof this.url, "string", "context is settings on callback " + msg );
583 jQuery('#foo').add(context)
590 url: url("data/name.html"),
591 beforeSend: callback("beforeSend"),
592 success: callback("success"),
593 error: callback("error"),
595 callback("complete").call(this);
598 url: url("data/404.html"),
600 beforeSend: callback("beforeSend"),
601 error: callback("error"),
602 complete: function(){
603 callback("complete").call(this);
605 jQuery('#foo').add(context).unbind();
608 url: url("data/404.html"),
609 beforeSend: nocallback("beforeSend"),
610 error: nocallback("error"),
611 complete: function(){
612 nocallback("complete").call(this);
623 test("jQuery.ajax context modification", function() {
631 url: url("data/name.html"),
633 beforeSend: function(){
636 complete: function() {
641 equals( obj.test, "foo", "Make sure the original object is maintained." );
644 test("jQuery.ajax() - disabled globals", function() {
648 jQuery('#foo').ajaxStart(function(){
649 ok( false, "ajaxStart" );
650 }).ajaxStop(function(){
651 ok( false, "ajaxStop" );
652 }).ajaxSend(function(){
653 ok( false, "ajaxSend" );
654 }).ajaxComplete(function(){
655 ok( false, "ajaxComplete" );
656 }).ajaxError(function(){
657 ok( false, "ajaxError" );
658 }).ajaxSuccess(function(){
659 ok( false, "ajaxSuccess" );
664 url: url("data/name.html"),
665 beforeSend: function(){ ok(true, "beforeSend"); },
666 success: function(){ ok(true, "success"); },
667 error: function(){ ok(false, "error"); },
668 complete: function(){
669 ok(true, "complete");
670 setTimeout(function(){ start(); }, 13);
675 test("jQuery.xhr() - disabled globals through xhr.send(data , false)", function() {
679 jQuery('#foo').ajaxStart(function(){
680 ok( false, "ajaxStart" );
681 }).ajaxStop(function(){
682 ok( false, "ajaxStop" );
683 }).ajaxSend(function(){
684 ok( false, "ajaxSend" );
685 }).ajaxComplete(function(){
686 ok( false, "ajaxComplete" );
687 }).ajaxError(function(){
688 ok( false, "ajaxError" );
689 }).ajaxSuccess(function(){
690 ok( false, "ajaxSuccess" );
694 .success(function(){ ok(true, "success"); })
695 .error(function(){ ok(false, "error"); })
696 .complete(function(){
697 ok(true, "complete");
698 setTimeout(function(){ start(); }, 13);
700 .open("GET", url("data/name.html")).send(undefined, false);
703 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
707 url: url("data/with_fries.xml"),
709 success: function(resp) {
710 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
711 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
712 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
718 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over JSONP)", function() {
722 url: url("data/with_fries_over_jsonp.php"),
723 dataType: "jsonp xml",
724 success: function(resp) {
725 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
726 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
727 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
733 test("jQuery.ajax - HEAD requests", function() {
738 url: url("data/name.html"),
740 success: function(data, status, xhr){
741 var h = xhr.getAllResponseHeaders();
742 ok( /Date/i.test(h), 'No Date in HEAD response' );
745 url: url("data/name.html"),
746 data: { whip_it: "good" },
748 success: function(data, status, xhr){
749 var h = xhr.getAllResponseHeaders();
750 ok( /Date/i.test(h), 'No Date in HEAD response with data' );
759 test("jQuery.ajax - beforeSend", function() {
765 jQuery.ajaxSetup({ timeout: 0 });
768 url: url("data/name.html"),
769 beforeSend: function(xml) {
772 success: function(data) {
773 ok( check, "check beforeSend was executed" );
779 test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
781 var request = jQuery.ajax({
782 url: url("data/name.html"),
783 beforeSend: function() {
784 ok( true, "beforeSend got called, canceling" );
787 success: function() {
788 ok( false, "request didn't get canceled" );
790 complete: function() {
791 ok( false, "request didn't get canceled" );
794 ok( false, "request didn't get canceled" );
797 ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
800 test("jQuery.ajax - beforeSend, cancel request manually", function() {
802 var request = jQuery.ajax({
803 url: url("data/name.html"),
804 beforeSend: function(xhr) {
805 ok( true, "beforeSend got called, canceling" );
808 success: function() {
809 ok( false, "request didn't get canceled" );
811 complete: function() {
812 ok( false, "request didn't get canceled" );
815 ok( false, "request didn't get canceled" );
818 ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
821 window.foobar = null;
822 window.testFoo = undefined;
824 test("jQuery.ajax - dataType html", function() {
828 var verifyEvaluation = function() {
829 equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
830 equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
837 url: url("data/test.html"),
838 success: function(data) {
839 jQuery("#ap").html(data);
840 ok( data.match(/^html text/), 'Check content for datatype html' );
841 setTimeout(verifyEvaluation, 600);
846 test("serialize()", function() {
849 // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
850 jQuery("#search").after(
851 '<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+
852 '<input type="number" id="html5number" name="number" value="43" />'
855 equals( jQuery('#form').serialize(),
856 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
857 'Check form serialization as query string');
859 equals( jQuery('#form :input').serialize(),
860 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
861 'Check input serialization as query string');
863 equals( jQuery('#testForm').serialize(),
864 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
865 'Check form serialization as query string');
867 equals( jQuery('#testForm :input').serialize(),
868 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
869 'Check input serialization as query string');
871 equals( jQuery('#form, #testForm').serialize(),
872 "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
873 'Multiple form serialization as query string');
875 /* Temporarily disabled. Opera 10 has problems with form serialization.
876 equals( jQuery('#form, #testForm :input').serialize(),
877 "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=",
878 'Mixed form/input serialization as query string');
880 jQuery("#html5email, #html5number").remove();
883 test("jQuery.param()", function() {
886 equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
888 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
889 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
891 params = {someName: [1, 2, 3], regularThing: "blah" };
892 equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" );
894 params = {foo: ['a', 'b', 'c']};
895 equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
897 params = {foo: ["baz", 42, "All your base are belong to us"] };
898 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
900 params = {foo: { bar: 'baz', beep: 42, quux: 'All your base are belong to us' } };
901 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" );
903 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?" };
904 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" );
906 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 ] };
907 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" );
909 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?" };
910 equals( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
912 equals( decodeURIComponent( jQuery.param({ a: [1,2,3], 'b[]': [4,5,6], 'c[d]': [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
914 // Make sure empty arrays and objects are handled #6481
915 equals( jQuery.param({"foo": {"bar": []} }), "foo%5Bbar%5D=", "Empty array param" );
916 equals( jQuery.param({"foo": {"bar": [], foo: 1} }), "foo%5Bbar%5D=&foo%5Bfoo%5D=1", "Empty array param" );
917 equals( jQuery.param({"foo": {"bar": {}} }), "foo%5Bbar%5D=", "Empty object param" );
919 jQuery.ajaxSetup({ traditional: true });
921 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
922 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
924 params = {someName: [1, 2, 3], regularThing: "blah" };
925 equals( jQuery.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" );
927 params = {foo: ['a', 'b', 'c']};
928 equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
930 params = {"foo[]":["baz", 42, "All your base are belong to us"]};
931 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
933 params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
934 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" );
936 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?" };
937 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" );
939 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 ] };
940 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)" );
942 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?" };
943 equals( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
945 params = { param1: null };
946 equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
949 test("synchronous request", function() {
951 ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );
954 test("synchronous request with callbacks", function() {
957 jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } });
958 ok( /^{ "data"/.test( result ), "check returned text" );
961 test("pass-through request object", function() {
965 var target = "data/name.html";
966 var successCount = 0;
969 var success = function() {
972 jQuery("#foo").ajaxError(function (e, xml, s, ex) {
974 errorEx += ": " + xml.status;
976 jQuery("#foo").one('ajaxStop', function () {
977 equals(successCount, 5, "Check all ajax calls successful");
978 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
979 jQuery("#foo").unbind('ajaxError');
984 ok( jQuery.get(url(target), success), "get" );
985 ok( jQuery.post(url(target), success), "post" );
986 ok( jQuery.getScript(url("data/test.js"), success), "script" );
987 ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
988 ok( jQuery.ajax({url: url(target), success: success}), "generic" );
991 test("ajax cache", function () {
998 jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
999 var re = /_=(.*?)(&|$)/g;
1001 for (var i = 0; i < 6; i++) {
1002 var ret = re.exec(s.url);
1008 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
1009 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
1014 ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
1015 ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
1016 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
1017 ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
1018 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
1019 ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
1024 * The assertions expect that the passed-in object will be modified,
1025 * which shouldn't be the case. Fixes #5439.
1026 test("global ajaxSettings", function() {
1029 var tmp = jQuery.extend({}, jQuery.ajaxSettings);
1030 var orig = { url: "data/with_fries.xml" };
1033 jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
1035 t = jQuery.extend({}, orig);
1038 ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
1040 t = jQuery.extend({}, orig);
1041 t.data = { zoo: 'a', ping: 'b' };
1043 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' }" );
1045 jQuery.ajaxSettings = tmp;
1049 test("load(String)", function() {
1051 stop(); // check if load can be called with only url
1052 jQuery('#first').load("data/name.html", start);
1055 test("load('url selector')", function() {
1057 stop(); // check if load can be called with only url
1058 jQuery('#first').load("data/test3.html div.user", function(){
1059 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
1064 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
1067 jQuery.ajaxSetup({ dataType: "json" });
1068 jQuery("#first").ajaxComplete(function (e, xml, s) {
1069 equals( s.dataType, "html", "Verify the load() dataType was html" );
1070 jQuery("#first").unbind("ajaxComplete");
1071 jQuery.ajaxSetup({ dataType: "" });
1074 jQuery('#first').load("data/test3.html");
1077 test("load(String, Function) - simple: inject text into DOM", function() {
1080 jQuery('#first').load(url("data/name.html"), function() {
1081 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
1086 test("load(String, Function) - check scripts", function() {
1090 var verifyEvaluation = function() {
1091 equals( foobar, "bar", 'Check if script src was evaluated after load' );
1092 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
1096 jQuery('#first').load(url('data/test.html'), function() {
1097 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
1098 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1099 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1100 setTimeout(verifyEvaluation, 600);
1104 test("load(String, Function) - check file with only a script tag", function() {
1108 jQuery('#first').load(url('data/test2.html'), function() {
1109 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
1110 equals( testFoo, "foo", 'Check if script was evaluated after load' );
1116 test("load(String, Object, Function)", function() {
1120 jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
1121 var $post = jQuery(this).find('#post');
1122 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
1123 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
1128 test("load(String, String, Function)", function() {
1132 jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
1133 var $get = jQuery(this).find('#get');
1134 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
1135 equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly');
1140 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
1143 jQuery.get(url('data/dashboard.xml'), function(xml) {
1145 jQuery('tab', xml).each(function() {
1146 content.push(jQuery(this).text());
1148 equals( content[0], 'blabla', 'Check first tab');
1149 equals( content[1], 'blublu', 'Check second tab');
1154 test("jQuery.getScript(String, Function) - with callback", function() {
1157 jQuery.getScript(url("data/test.js"), function() {
1158 equals( foobar, "bar", 'Check if script was evaluated' );
1159 setTimeout(start, 100);
1163 test("jQuery.getScript(String, Function) - no callback", function() {
1166 jQuery.getScript(url("data/test.js"), function(){
1171 test("jQuery.ajax() - JSONP, Local", function() {
1175 function plus(){ if ( ++count == 9 ) start(); }
1180 url: "data/jsonp.php",
1182 success: function(data){
1183 ok( data.data, "JSON results returned (GET, no callback)" );
1186 error: function(data){
1187 ok( false, "Ajax error JSON (GET, no callback)" );
1193 url: "data/jsonp.php?callback=?",
1195 success: function(data){
1196 ok( data.data, "JSON results returned (GET, url callback)" );
1199 error: function(data){
1200 ok( false, "Ajax error JSON (GET, url callback)" );
1206 url: "data/jsonp.php",
1209 success: function(data){
1210 ok( data.data, "JSON results returned (GET, data callback)" );
1213 error: function(data){
1214 ok( false, "Ajax error JSON (GET, data callback)" );
1220 url: "data/jsonp.php",
1223 success: function(data){
1224 ok( data.data, "JSON results returned (GET, data obj callback)" );
1227 error: function(data){
1228 ok( false, "Ajax error JSON (GET, data obj callback)" );
1234 url: "data/jsonp.php",
1236 jsonpCallback: "jsonpResults",
1237 success: function(data){
1238 ok( data.data, "JSON results returned (GET, custom callback name)" );
1241 error: function(data){
1242 ok( false, "Ajax error JSON (GET, custom callback name)" );
1249 url: "data/jsonp.php",
1251 success: function(data){
1252 ok( data.data, "JSON results returned (POST, no callback)" );
1255 error: function(data){
1256 ok( false, "Ajax error JSON (GET, data obj callback)" );
1263 url: "data/jsonp.php",
1266 success: function(data){
1267 ok( data.data, "JSON results returned (POST, data callback)" );
1270 error: function(data){
1271 ok( false, "Ajax error JSON (POST, data callback)" );
1278 url: "data/jsonp.php",
1281 success: function(data){
1282 ok( data.data, "JSON results returned (POST, data obj callback)" );
1285 error: function(data){
1286 ok( false, "Ajax error JSON (POST, data obj callback)" );
1293 url: "data/jsonp.php",
1295 beforeSend: function(){
1296 strictEqual( this.cache, false, "cache must be false on JSON request" );
1303 test("jQuery.ajax() - JSONP - Custom JSONP Callback", function() {
1307 window.jsonpResults = function(data) {
1308 ok( data.data, "JSON results returned (GET, custom callback function)" );
1309 window.jsonpResults = undefined;
1314 url: "data/jsonp.php",
1316 jsonpCallback: "jsonpResults"
1320 test("jQuery.ajax() - JSONP, Remote", function() {
1324 function plus(){ if ( ++count == 4 ) start(); }
1326 var base = window.location.href.replace(/[^\/]*$/, "");
1331 url: base + "data/jsonp.php",
1333 success: function(data){
1334 ok( data.data, "JSON results returned (GET, no callback)" );
1337 error: function(data){
1338 ok( false, "Ajax error JSON (GET, no callback)" );
1344 url: base + "data/jsonp.php?callback=?",
1346 success: function(data){
1347 ok( data.data, "JSON results returned (GET, url callback)" );
1350 error: function(data){
1351 ok( false, "Ajax error JSON (GET, url callback)" );
1357 url: base + "data/jsonp.php",
1360 success: function(data){
1361 ok( data.data, "JSON results returned (GET, data callback)" );
1364 error: function(data){
1365 ok( false, "Ajax error JSON (GET, data callback)" );
1371 url: base + "data/jsonp.php",
1374 success: function(data){
1375 ok( data.data, "JSON results returned (GET, data obj callback)" );
1378 error: function(data){
1379 ok( false, "Ajax error JSON (GET, data obj callback)" );
1385 test("jQuery.ajax() - script, Remote", function() {
1388 var base = window.location.href.replace(/[^\/]*$/, "");
1393 url: base + "data/test.js",
1395 success: function(data){
1396 ok( foobar, "Script results returned (GET, no callback)" );
1402 test("jQuery.ajax() - script, Remote with POST", function() {
1405 var base = window.location.href.replace(/[^\/]*$/, "");
1410 url: base + "data/test.js",
1413 success: function(data, status){
1414 ok( foobar, "Script results returned (POST, no callback)" );
1415 equals( status, "success", "Script results returned (POST, no callback)" );
1418 error: function(xhr) {
1419 ok( false, "ajax error, status code: " + xhr.status );
1425 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
1428 var base = window.location.href.replace(/[^\/]*$/, "");
1429 base = base.replace(/^.*?\/\//, "//");
1434 url: base + "data/test.js",
1436 success: function(data){
1437 ok( foobar, "Script results returned (GET, no callback)" );
1443 test("jQuery.ajax() - malformed JSON", function() {
1449 url: "data/badjson.js",
1451 success: function(){
1452 ok( false, "Success." );
1455 error: function(xhr, msg, detailedMsg) {
1456 equals( "parsererror", msg, "A parse error occurred." );
1457 ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" );
1463 test("jQuery.ajax() - script by content-type", function() {
1469 url: "data/script.php",
1470 data: { header: "script" },
1471 success: function() {
1477 test("jQuery.ajax() - json by content-type", function() {
1483 url: "data/json.php",
1484 data: { header: "json", json: "array" },
1485 success: function( json ) {
1486 ok( json.length >= 2, "Check length");
1487 equals( json[0].name, 'John', 'Check JSON: first, name' );
1488 equals( json[0].age, 21, 'Check JSON: first, age' );
1489 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1490 equals( json[1].age, 25, 'Check JSON: second, age' );
1496 test("jQuery.ajax() - json by content-type disabled with options", function() {
1502 url: url("data/json.php"),
1503 data: { header: "json", json: "array" },
1507 success: function( text ) {
1508 equals( typeof text , "string" , "json wasn't auto-determined" );
1509 var json = this.dataConverters["text => json"]( text );
1510 ok( json.length >= 2, "Check length");
1511 equals( json[0].name, 'John', 'Check JSON: first, name' );
1512 equals( json[0].age, 21, 'Check JSON: first, age' );
1513 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1514 equals( json[1].age, 25, 'Check JSON: second, age' );
1520 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
1523 jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
1524 ok( json.length >= 2, "Check length");
1525 equals( json[0].name, 'John', 'Check JSON: first, name' );
1526 equals( json[0].age, 21, 'Check JSON: first, age' );
1527 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
1528 equals( json[1].age, 25, 'Check JSON: second, age' );
1533 test("jQuery.getJSON(String, Function) - JSON object", function() {
1536 jQuery.getJSON(url("data/json.php"), function(json) {
1537 if (json && json.data) {
1538 equals( json.data.lang, 'en', 'Check JSON: lang' );
1539 equals( json.data.length, 25, 'Check JSON: length' );
1545 test("jQuery.getJSON - Using Native JSON", function() {
1548 var old = window.JSON;
1550 parse: function(str){
1551 ok( true, "Verifying that parse method was run" );
1557 jQuery.getJSON(url("data/json.php"), function(json) {
1559 equals( json, true, "Verifying return value" );
1564 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
1567 var base = window.location.href.replace(/[^\/]*$/, "");
1570 jQuery.getJSON(url(base + "data/json.php"), function(json) {
1571 equals( json.data.lang, 'en', 'Check JSON: lang' );
1572 equals( json.data.length, 25, 'Check JSON: length' );
1577 test("jQuery.post - data", function() {
1581 jQuery.post(url("data/name.php"), {xml: "5-2", length: 3}, function(xml){
1582 jQuery('math', xml).each(function() {
1583 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1584 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1590 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
1595 jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
1596 jQuery('math', xml).each(function() {
1597 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1598 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1600 if ( ++done === 2 ) start();
1603 jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
1604 jQuery('math', xml).each(function() {
1605 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
1606 equals( jQuery('result', this).text(), '3', 'Check for XML' );
1608 if ( ++done === 2 ) start();
1612 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
1617 jQuery.ajaxSetup({timeout: 1000});
1619 var pass = function() {
1621 if ( passed == 2 ) {
1622 ok( true, 'Check local and global callbacks after timeout' );
1623 jQuery('#main').unbind("ajaxError");
1628 var fail = function(a,b,c) {
1629 ok( false, 'Check for timeout failed ' + a + ' ' + b );
1633 jQuery('#main').ajaxError(pass);
1637 url: url("data/name.php?wait=5"),
1643 jQuery.ajaxSetup({timeout: 0});
1646 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
1648 jQuery.ajaxSetup({timeout: 50});
1653 url: url("data/name.php?wait=1"),
1655 ok( false, 'Check for local timeout failed' );
1658 success: function() {
1659 ok( true, 'Check for local timeout' );
1665 jQuery.ajaxSetup({timeout: 0});
1668 test("jQuery.ajax - simple get", function() {
1673 url: url("data/name.php?name=foo"),
1674 success: function(msg){
1675 equals( msg, 'bar', 'Check for GET' );
1681 test("jQuery.ajax - simple post", function() {
1686 url: url("data/name.php"),
1688 success: function(msg){
1689 equals( msg, 'pan', 'Check for POST' );
1695 test("ajaxSetup()", function() {
1699 url: url("data/name.php?name=foo"),
1700 success: function(msg){
1701 equals( msg, 'bar', 'Check for GET' );
1709 test("custom timeout does not set error message when timeout occurs, see #970", function() {
1712 url: "data/name.php?wait=1",
1714 error: function(request, status) {
1715 ok( status != null, "status shouldn't be null in error handler" );
1716 equals( "timeout", status );
1723 test("data option: evaluate function values (#2806)", function() {
1726 url: "data/echoQuery.php",
1732 success: function(result) {
1733 equals( result, "key=value" );
1739 test("data option: empty bodies for non-GET requests", function() {
1742 url: "data/echoData.php",
1745 success: function(result) {
1746 equals( result, "" );
1752 test("jQuery.ajax - If-Modified-Since support", function() {
1757 var url = "data/if_modified_since.php?ts=" + new Date();
1762 success: function(data, status) {
1763 equals(status, "success");
1768 success: function(data, status) {
1769 if ( data === "FAIL" ) {
1770 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1771 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1773 equals(status, "notmodified");
1774 ok(data == null, "response body should be empty")
1779 // Do this because opera simply refuses to implement 304 handling :(
1780 // A feature-driven way of detecting this would be appreciated
1781 // See: http://gist.github.com/599419
1782 ok(jQuery.browser.opera, "error");
1783 ok(jQuery.browser.opera, "error");
1789 equals(false, "error");
1790 // Do this because opera simply refuses to implement 304 handling :(
1791 // A feature-driven way of detecting this would be appreciated
1792 // See: http://gist.github.com/599419
1793 ok(jQuery.browser.opera, "error");
1799 test("jQuery.ajax - Etag support", function() {
1804 var url = "data/etag.php?ts=" + new Date();
1809 success: function(data, status) {
1810 equals(status, "success");
1815 success: function(data, status) {
1816 if ( data === "FAIL" ) {
1817 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1818 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1820 equals(status, "notmodified");
1821 ok(data == null, "response body should be empty")
1826 // Do this because opera simply refuses to implement 304 handling :(
1827 // A feature-driven way of detecting this would be appreciated
1828 // See: http://gist.github.com/599419
1829 ok(jQuery.browser.opera, "error");
1830 ok(jQuery.browser.opera, "error");
1836 // Do this because opera simply refuses to implement 304 handling :(
1837 // A feature-driven way of detecting this would be appreciated
1838 // See: http://gist.github.com/599419
1839 ok(jQuery.browser.opera, "error");
1845 test("jQuery ajax - failing cross-domain", function() {
1854 url: 'http://somewebsitethatdoesnotexist.com',
1855 success: function(){ ok( false , "success" ); },
1856 error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
1857 complete: function() { if ( ! --i ) start(); }
1861 url: 'http://www.google.com',
1862 success: function(){ ok( false , "success" ); },
1863 error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
1864 complete: function() { if ( ! --i ) start(); }
1869 test("jQuery ajax - atom+xml", function() {
1874 url: url( 'data/atom+xml.php' ),
1875 success: function(){ ok( true , "success" ); },
1876 error: function(){ ok( false , "error" ); },
1877 complete: function() { start(); }
1882 test("jQuery.ajax - active counter", function() {
1883 ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
1886 test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
1887 var success = false;
1889 var xhr = jQuery.ajax({ url: document.location });
1894 ok( success, "document.location did not generate exception" );