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("jQuery.ajax() - abort", function() {
77 jQuery('#foo').ajaxStart(function(){
78 ok( true, "ajaxStart" );
79 }).ajaxStop(function(){
80 ok( true, "ajaxStop" );
82 }).ajaxSend(function(){
83 ok( true, "ajaxSend" );
84 }).ajaxComplete(function(){
85 ok( true, "ajaxComplete" );
88 var xhr = jQuery.ajax({
89 url: url("data/name.php?wait=5"),
90 beforeSend: function(){ ok(true, "beforeSend"); },
91 complete: function(){ ok(true, "complete"); }
97 test("Ajax events with context", function() {
101 var context = document.createElement("div");
104 equals( this, context, e.type );
108 equals( this, context, "context is preserved on callback" );
111 jQuery('#foo').add(context)
118 url: url("data/name.html"),
119 beforeSend: callback,
124 setTimeout(proceed, 300);
130 jQuery('#foo').add(context).unbind();
135 test("jQuery.ajax() - disabled globals", function() {
139 jQuery('#foo').ajaxStart(function(){
140 ok( false, "ajaxStart" );
141 }).ajaxStop(function(){
142 ok( false, "ajaxStop" );
143 }).ajaxSend(function(){
144 ok( false, "ajaxSend" );
145 }).ajaxComplete(function(){
146 ok( false, "ajaxComplete" );
147 }).ajaxError(function(){
148 ok( false, "ajaxError" );
149 }).ajaxSuccess(function(){
150 ok( false, "ajaxSuccess" );
155 url: url("data/name.html"),
156 beforeSend: function(){ ok(true, "beforeSend"); },
157 success: function(){ ok(true, "success"); },
158 error: function(){ ok(false, "error"); },
159 complete: function(){
160 ok(true, "complete");
161 setTimeout(function(){ start(); }, 13);
166 test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
170 url: url("data/with_fries.xml"),
172 success: function(resp) {
173 equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
174 equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
175 equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
181 test("jQuery.ajax - beforeSend", function() {
187 jQuery.ajaxSetup({ timeout: 0 });
190 url: url("data/name.html"),
191 beforeSend: function(xml) {
194 success: function(data) {
195 ok( check, "check beforeSend was executed" );
201 test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
203 var request = jQuery.ajax({
204 url: url("data/name.html"),
205 beforeSend: function() {
206 ok( true, "beforeSend got called, canceling" );
209 success: function() {
210 ok( false, "request didn't get canceled" );
212 complete: function() {
213 ok( false, "request didn't get canceled" );
216 ok( false, "request didn't get canceled" );
219 ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
222 window.foobar = null;
223 window.testFoo = undefined;
225 test("jQuery.ajax - dataType html", function() {
229 var verifyEvaluation = function() {
230 equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
231 equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
238 url: url("data/test.html"),
239 success: function(data) {
240 jQuery("#ap").html(data);
241 ok( data.match(/^html text/), 'Check content for datatype html' );
242 setTimeout(verifyEvaluation, 600);
247 test("serialize()", function() {
250 // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
251 jQuery("#search").after(
252 '<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+
253 '<input type="number" id="html5number" name="number" value="43" />'
256 equals( jQuery('#form').serialize(),
257 "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",
258 'Check form serialization as query string');
260 equals( jQuery('#form :input').serialize(),
261 "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",
262 'Check input serialization as query string');
264 equals( jQuery('#testForm').serialize(),
265 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
266 'Check form serialization as query string');
268 equals( jQuery('#testForm :input').serialize(),
269 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
270 'Check input serialization as query string');
272 equals( jQuery('#form, #testForm').serialize(),
273 "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=",
274 'Multiple form serialization as query string');
276 /* Temporarily disabled. Opera 10 has problems with form serialization.
277 equals( jQuery('#form, #testForm :input').serialize(),
278 "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=",
279 'Mixed form/input serialization as query string');
281 jQuery("#html5email, #html5number").remove();
284 test("jQuery.param()", function() {
287 equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
289 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
290 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
292 params = {someName: [1, 2, 3], regularThing: "blah" };
293 equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" );
295 params = {foo: ['a', 'b', 'c']};
296 equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
298 params = {foo: ["baz", 42, "All your base are belong to us"] };
299 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
301 params = {foo: { bar: 'baz', beep: 42, quux: 'All your base are belong to us' } };
302 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" );
304 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?" };
305 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" );
307 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 ] };
308 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" );
310 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?" };
311 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" );
313 jQuery.ajaxSetup({ traditional: true });
315 var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
316 equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
318 params = {someName: [1, 2, 3], regularThing: "blah" };
319 equals( jQuery.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" );
321 params = {foo: ['a', 'b', 'c']};
322 equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
324 params = {"foo[]":["baz", 42, "All your base are belong to us"]};
325 equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
327 params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
328 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" );
330 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?" };
331 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" );
333 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 ] };
334 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)" );
336 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?" };
337 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" );
342 test("synchronous request", function() {
344 ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );
347 test("synchronous request with callbacks", function() {
350 jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } });
351 ok( /^{ "data"/.test( result ), "check returned text" );
354 test("pass-through request object", function() {
358 var target = "data/name.html";
359 var successCount = 0;
362 var success = function() {
365 jQuery("#foo").ajaxError(function (e, xml, s, ex) {
367 errorEx += ": " + xml.status;
369 jQuery("#foo").one('ajaxStop', function () {
370 equals(successCount, 5, "Check all ajax calls successful");
371 equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
372 jQuery("#foo").unbind('ajaxError');
377 ok( jQuery.get(url(target), success), "get" );
378 ok( jQuery.post(url(target), success), "post" );
379 ok( jQuery.getScript(url("data/test.js"), success), "script" );
380 ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" );
381 ok( jQuery.ajax({url: url(target), success: success}), "generic" );
384 test("ajax cache", function () {
391 jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) {
392 var re = /_=(.*?)(&|$)/g;
394 for (var i = 0; i < 6; i++) {
395 var ret = re.exec(s.url);
401 equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
402 ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
407 ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
408 ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
409 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
410 ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
411 ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
412 ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
417 * The assertions expect that the passed-in object will be modified,
418 * which shouldn't be the case. Fixes #5439.
419 test("global ajaxSettings", function() {
422 var tmp = jQuery.extend({}, jQuery.ajaxSettings);
423 var orig = { url: "data/with_fries.xml" };
426 jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
428 t = jQuery.extend({}, orig);
431 ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
433 t = jQuery.extend({}, orig);
434 t.data = { zoo: 'a', ping: 'b' };
436 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' }" );
438 jQuery.ajaxSettings = tmp;
442 test("load(String)", function() {
444 stop(); // check if load can be called with only url
445 jQuery('#first').load("data/name.html", start);
448 test("load('url selector')", function() {
450 stop(); // check if load can be called with only url
451 jQuery('#first').load("data/test3.html div.user", function(){
452 equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
457 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
460 jQuery.ajaxSetup({ dataType: "json" });
461 jQuery("#first").ajaxComplete(function (e, xml, s) {
462 equals( s.dataType, "html", "Verify the load() dataType was html" );
463 jQuery("#first").unbind("ajaxComplete");
464 jQuery.ajaxSetup({ dataType: "" });
467 jQuery('#first').load("data/test3.html");
470 test("load(String, Function) - simple: inject text into DOM", function() {
473 jQuery('#first').load(url("data/name.html"), function() {
474 ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
479 test("load(String, Function) - check scripts", function() {
483 var verifyEvaluation = function() {
484 equals( foobar, "bar", 'Check if script src was evaluated after load' );
485 equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
489 jQuery('#first').load(url('data/test.html'), function() {
490 ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
491 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
492 equals( testFoo, "foo", 'Check if script was evaluated after load' );
493 setTimeout(verifyEvaluation, 600);
497 test("load(String, Function) - check file with only a script tag", function() {
501 jQuery('#first').load(url('data/test2.html'), function() {
502 equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
503 equals( testFoo, "foo", 'Check if script was evaluated after load' );
509 test("load(String, Object, Function)", function() {
513 jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
514 var $post = jQuery(this).find('#post');
515 equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
516 equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
521 test("load(String, String, Function)", function() {
525 jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
526 var $get = jQuery(this).find('#get');
527 equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
528 equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly');
533 test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
536 jQuery.get(url('data/dashboard.xml'), function(xml) {
538 jQuery('tab', xml).each(function() {
539 content.push(jQuery(this).text());
541 equals( content[0], 'blabla', 'Check first tab');
542 equals( content[1], 'blublu', 'Check second tab');
547 test("jQuery.getScript(String, Function) - with callback", function() {
550 jQuery.getScript(url("data/test.js"), function() {
551 equals( foobar, "bar", 'Check if script was evaluated' );
552 setTimeout(start, 100);
556 test("jQuery.getScript(String, Function) - no callback", function() {
559 jQuery.getScript(url("data/test.js"), function(){
564 test("jQuery.ajax() - JSONP, Local", function() {
568 function plus(){ if ( ++count == 8 ) start(); }
573 url: "data/jsonp.php",
575 success: function(data){
576 ok( data.data, "JSON results returned (GET, no callback)" );
579 error: function(data){
580 ok( false, "Ajax error JSON (GET, no callback)" );
586 url: "data/jsonp.php?callback=?",
588 success: function(data){
589 ok( data.data, "JSON results returned (GET, url callback)" );
592 error: function(data){
593 ok( false, "Ajax error JSON (GET, url callback)" );
599 url: "data/jsonp.php",
602 success: function(data){
603 ok( data.data, "JSON results returned (GET, data callback)" );
606 error: function(data){
607 ok( false, "Ajax error JSON (GET, data callback)" );
613 url: "data/jsonp.php",
616 success: function(data){
617 ok( data.data, "JSON results returned (GET, data obj callback)" );
620 error: function(data){
621 ok( false, "Ajax error JSON (GET, data obj callback)" );
627 url: "data/jsonp.php",
629 jsonpCallback: "jsonpResults",
630 success: function(data){
631 ok( data.data, "JSON results returned (GET, custom callback name)" );
634 error: function(data){
635 ok( false, "Ajax error JSON (GET, custom callback name)" );
642 url: "data/jsonp.php",
644 success: function(data){
645 ok( data.data, "JSON results returned (POST, no callback)" );
648 error: function(data){
649 ok( false, "Ajax error JSON (GET, data obj callback)" );
656 url: "data/jsonp.php",
659 success: function(data){
660 ok( data.data, "JSON results returned (POST, data callback)" );
663 error: function(data){
664 ok( false, "Ajax error JSON (POST, data callback)" );
671 url: "data/jsonp.php",
674 success: function(data){
675 ok( data.data, "JSON results returned (POST, data obj callback)" );
678 error: function(data){
679 ok( false, "Ajax error JSON (POST, data obj callback)" );
685 test("JSONP - Custom JSONP Callback", function() {
689 window.jsonpResults = function(data) {
690 ok( data.data, "JSON results returned (GET, custom callback function)" );
695 url: "data/jsonp.php",
697 jsonpCallback: "jsonpResults"
701 test("jQuery.ajax() - JSONP, Remote", function() {
705 function plus(){ if ( ++count == 4 ) start(); }
707 var base = window.location.href.replace(/\?.*$/, "");
712 url: base + "data/jsonp.php",
714 success: function(data){
715 ok( data.data, "JSON results returned (GET, no callback)" );
718 error: function(data){
719 ok( false, "Ajax error JSON (GET, no callback)" );
725 url: base + "data/jsonp.php?callback=?",
727 success: function(data){
728 ok( data.data, "JSON results returned (GET, url callback)" );
731 error: function(data){
732 ok( false, "Ajax error JSON (GET, url callback)" );
738 url: base + "data/jsonp.php",
741 success: function(data){
742 ok( data.data, "JSON results returned (GET, data callback)" );
745 error: function(data){
746 ok( false, "Ajax error JSON (GET, data callback)" );
752 url: base + "data/jsonp.php",
755 success: function(data){
756 ok( data.data, "JSON results returned (GET, data obj callback)" );
759 error: function(data){
760 ok( false, "Ajax error JSON (GET, data obj callback)" );
766 test("jQuery.ajax() - script, Remote", function() {
769 var base = window.location.href.replace(/\?.*$/, "");
774 url: base + "data/test.js",
776 success: function(data){
777 ok( foobar, "Script results returned (GET, no callback)" );
783 test("jQuery.ajax() - script, Remote with POST", function() {
786 var base = window.location.href.replace(/\?.*$/, "");
791 url: base + "data/test.js",
794 success: function(data, status){
795 ok( foobar, "Script results returned (POST, no callback)" );
796 equals( status, "success", "Script results returned (POST, no callback)" );
799 error: function(xhr) {
800 ok( false, "ajax error, status code: " + xhr.status );
806 test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
809 var base = window.location.href.replace(/\?.*$/, "");
810 base = base.replace(/^.*?\/\//, "//");
815 url: base + "data/test.js",
817 success: function(data){
818 ok( foobar, "Script results returned (GET, no callback)" );
824 test("jQuery.ajax() - malformed JSON", function() {
830 url: "data/badjson.js",
833 ok( false, "Success." );
836 error: function(xhr, msg) {
837 equals( "parsererror", msg, "A parse error occurred." );
843 test("jQuery.ajax() - script by content-type", function() {
849 url: "data/script.php",
850 data: { header: "script" },
851 success: function() {
857 test("jQuery.ajax() - json by content-type", function() {
863 url: "data/json.php",
864 data: { header: "json", json: "array" },
865 success: function( json ) {
866 ok( json.length >= 2, "Check length");
867 equals( json[0].name, 'John', 'Check JSON: first, name' );
868 equals( json[0].age, 21, 'Check JSON: first, age' );
869 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
870 equals( json[1].age, 25, 'Check JSON: second, age' );
876 test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
879 jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
880 ok( json.length >= 2, "Check length");
881 equals( json[0].name, 'John', 'Check JSON: first, name' );
882 equals( json[0].age, 21, 'Check JSON: first, age' );
883 equals( json[1].name, 'Peter', 'Check JSON: second, name' );
884 equals( json[1].age, 25, 'Check JSON: second, age' );
889 test("jQuery.getJSON(String, Function) - JSON object", function() {
892 jQuery.getJSON(url("data/json.php"), function(json) {
893 if (json && json.data) {
894 equals( json.data.lang, 'en', 'Check JSON: lang' );
895 equals( json.data.length, 25, 'Check JSON: length' );
901 test("jQuery.getJSON - Using Native JSON", function() {
904 var old = window.JSON;
906 parse: function(str){
907 ok( true, "Verifying that parse method was run" );
913 jQuery.getJSON(url("data/json.php"), function(json) {
915 equals( json, true, "Verifying return value" );
920 test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() {
923 var base = window.location.href.replace(/\?.*$/, "");
926 jQuery.getJSON(url(base + "data/json.php"), function(json) {
927 equals( json.data.lang, 'en', 'Check JSON: lang' );
928 equals( json.data.length, 25, 'Check JSON: length' );
933 test("jQuery.post(String, Hash, Function) - simple with xml", function() {
938 jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
939 jQuery('math', xml).each(function() {
940 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
941 equals( jQuery('result', this).text(), '3', 'Check for XML' );
943 if ( ++done === 2 ) start();
946 jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
947 jQuery('math', xml).each(function() {
948 equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
949 equals( jQuery('result', this).text(), '3', 'Check for XML' );
951 if ( ++done === 2 ) start();
955 test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
960 jQuery.ajaxSetup({timeout: 1000});
962 var pass = function() {
965 ok( true, 'Check local and global callbacks after timeout' );
966 jQuery('#main').unbind("ajaxError");
971 var fail = function(a,b,c) {
972 ok( false, 'Check for timeout failed ' + a + ' ' + b );
976 jQuery('#main').ajaxError(pass);
980 url: url("data/name.php?wait=5"),
986 jQuery.ajaxSetup({timeout: 0});
989 test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
991 jQuery.ajaxSetup({timeout: 50});
996 url: url("data/name.php?wait=1"),
998 ok( false, 'Check for local timeout failed' );
1001 success: function() {
1002 ok( true, 'Check for local timeout' );
1008 jQuery.ajaxSetup({timeout: 0});
1011 test("jQuery.ajax - simple get", function() {
1016 url: url("data/name.php?name=foo"),
1017 success: function(msg){
1018 equals( msg, 'bar', 'Check for GET' );
1024 test("jQuery.ajax - simple post", function() {
1029 url: url("data/name.php"),
1031 success: function(msg){
1032 equals( msg, 'pan', 'Check for POST' );
1038 test("ajaxSetup()", function() {
1042 url: url("data/name.php?name=foo"),
1043 success: function(msg){
1044 equals( msg, 'bar', 'Check for GET' );
1052 test("custom timeout does not set error message when timeout occurs, see #970", function() {
1055 url: "data/name.php?wait=1",
1057 error: function(request, status) {
1058 ok( status != null, "status shouldn't be null in error handler" );
1059 equals( "timeout", status );
1066 test("data option: evaluate function values (#2806)", function() {
1069 url: "data/echoQuery.php",
1075 success: function(result) {
1076 equals( result, "key=value" );
1082 test("jQuery.ajax - If-Modified-Since support", function() {
1087 var url = "data/if_modified_since.php?ts=" + new Date();
1092 success: function(data, status) {
1093 equals(status, "success");
1098 success: function(data, status) {
1099 if ( data === "FAIL" ) {
1100 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1101 ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
1103 equals(status, "notmodified");
1104 ok(data == null, "response body should be empty")
1113 test("jQuery.ajax - Etag support", function() {
1118 var url = "data/etag.php?ts=" + new Date();
1123 success: function(data, status) {
1124 equals(status, "success");
1129 success: function(data, status) {
1130 if ( data === "FAIL" ) {
1131 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1132 ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
1134 equals(status, "notmodified");
1135 ok(data == null, "response body should be empty")