3 test("load(String, Object, Function) - simple: inject text into DOM", function() {
6 $('#first').load("data/name.php", function() {
7 ok( /^ERROR/.test($('#first').text()), 'Check if content was injected into the DOM' );
12 test("load(String, Object, Function) - inject without callback", function() {
14 stop(); // check if load can be called with only url
15 $('#first').load("data/name.php");
18 test("load(String, Object, Function) - check scripts", function() {
22 var verifyEvaluation = function() {
23 ok( foobar == "bar", 'Check if script src was evaluated after load' );
24 ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM');
25 ok( $('#ap').html() == 'bar', 'Check if script evaluation has modified DOM');
28 $('#first').load('data/test.html', function() {
29 ok( $('#first').html().match(/^html text/), 'Check content after loading html' );
30 ok( testFoo == "foo", 'Check if script was evaluated after load' );
31 setTimeout(verifyEvaluation, 600);
35 test("serialize()", function() {
37 var data = $(':input').not('button').serialize();
38 // ignore button, IE takes text content as value, not relevant for this test
39 ok( data == 'action=Test&text2=Test&radio1=on&radio2=on&check=on&=on&hidden=&foo[bar]=&name=name&=foobar&select1=&select2=3&select3=1', 'Check form serialization as query string' );
42 test("test global handlers - success", function() {
45 var counter = { complete: 0, success: 0, error: 0 },
46 success = function() { counter.success++ },
47 error = function() { counter.error++ },
48 complete = function() { counter.complete++ };
50 $('#foo').ajaxStart(complete).ajaxStop(complete).ajaxComplete(complete).ajaxError(error).ajaxSuccess(success);
51 // start with successful test
52 $.ajax({url: "data/name.php", success: success, error: error, complete: function() {
53 ok( counter.error == 0, 'Check succesful request' );
54 ok( counter.success == 2, 'Check succesful request' );
55 ok( counter.complete == 3, 'Check succesful request' );
56 counter.error = counter.success = counter.complete = 0;
58 $.ajax({url: "data/name.php?wait=5", success: success, error: error, complete: function() {
59 ok( counter.error == 2, 'Check failed request' );
60 ok( counter.success == 0, 'Check failed request' );
61 ok( counter.complete == 3, 'Check failed request' );
67 test("test global handlers - failure", function() {
70 var counter = { complete: 0, success: 0, error: 0 },
71 success = function() { counter.success++ },
72 error = function() { counter.error++ };
74 $.ajax({url: "data/name.php", global: false, success: success, error: error, complete: function() {
75 ok( counter.error == 0, 'Check sucesful request without globals' );
76 ok( counter.success == 1, 'Check sucesful request without globals' );
77 ok( counter.complete == 0, 'Check sucesful request without globals' );
78 counter.error = counter.success = counter.complete = 0;
80 $.ajax({url: "data/name.php?wait=5", global: false, success: success, error: error, complete: function() {
81 ok( counter.error == 1, 'Check failed request without globals' );
82 ok( counter.success == 0, 'Check failed request without globals' );
83 ok( counter.complete == 0, 'Check failed request without globals' );
89 test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
92 $.get('data/dashboard.xml', function(xml) {
94 $('tab', xml).each(function() {
95 content.push($(this).text());
97 ok( content[0] == 'blabla', 'Check first tab');
98 ok( content[1] == 'blublu', 'Check second tab');
103 test("$.getIfModified(String, Hash, Function)", function() {
106 $.getIfModified("data/name.php", function(msg) {
107 ok( /^ERROR/.test(msg), 'Check ifModified' );
112 test("$.getScript(String, Function) - with callback", function() {
115 $.getScript("data/test.js", function() {
116 ok( foobar == "bar", 'Check if script was evaluated' );
117 setTimeout(start, 100);
121 test("$.getScript(String, Function) - no callback", function() {
124 $.getScript("data/test.js");
127 test("$.getJSON(String, Hash, Function) - JSON array", function() {
130 $.getJSON("data/json.php", {json: "array"}, function(json) {
131 ok( json[0].name == 'John', 'Check JSON: first, name' );
132 ok( json[0].age == 21, 'Check JSON: first, age' );
133 ok( json[1].name == 'Peter', 'Check JSON: second, name' );
134 ok( json[1].age == 25, 'Check JSON: second, age' );
139 test("$.getJSON(String, Hash, Function) - JSON object", function() {
142 $.getJSON("data/json.php", function(json) {
143 ok( json.data.lang == 'en', 'Check JSON: lang' );
144 ok( json.data.length == 25, 'Check JSON: length' );
149 test("$.post(String, Hash, Function) - simple with xml", function() {
152 $.post("data/name.php", {xml: "5-2"}, function(xml){
153 $('math', xml).each(function() {
154 ok( $('calculation', this).text() == '5-2', 'Check for XML' );
155 ok( $('result', this).text() == '3', 'Check for XML' );
161 test("$.ajaxTimeout(Number) - with global timeout", function() {
166 var pass = function() {
169 ok( true, 'Check local and global callbacks after timeout' );
170 clearTimeout(timeout);
171 $('#main').unbind("ajaxError");
175 var fail = function() {
176 ok( false, 'Check for timeout failed' );
179 timeout = setTimeout(fail, 1500);
180 $('#main').ajaxError(pass);
183 url: "data/name.php?wait=5",
189 test("$.ajaxTimeout(Number) with localtimeout", function() {
190 stop(); $.ajaxTimeout(50);
194 url: "data/name.php?wait=1",
196 ok( false, 'Check for local timeout failed' );
199 success: function() {
200 ok( true, 'Check for local timeout' );
208 test("$.ajax - simple get", function() {
213 url: "data/name.php?name=foo",
214 success: function(msg){
215 ok( msg == 'bar', 'Check for GET' );
221 test("$.ajax - simple post", function() {
226 url: "data/name.php",
228 success: function(msg){
229 ok( msg == 'pan', 'Check for POST' );
235 test("$.ajax - dataType html", function() {
239 var verifyEvaluation = function() {
240 ok( foobar == "bar", 'Check if script src was evaluated for datatype html' );
245 url: "data/test.html",
246 success: function(data) {
247 ok( data.match(/^html text/), 'Check content for datatype html' );
248 ok( testFoo == "foo", 'Check if script was evaluated for datatype html' );
249 setTimeout(verifyEvaluation, 600);
254 test("$.ajax - xml: non-namespace elements inside namespaced elements", function() {
258 url: "data/with_fries.xml", dataType: "xml", type: "GET", data: "", success: function(resp) {
259 ok( $("properties", resp).length == 1, 'properties in responseXML' );
260 ok( $("jsconf", resp).length == 1, 'jsconf in responseXML' );
261 ok( $("thing", resp).length == 2, 'things in responseXML' );