3 test("load(String, Object, Function) - simple: inject text into DOM", function() {
6 $('#first').load("data/name.php", function() {
7 ok( $('#first').text() == 'ERROR', '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");
16 $.get("data/name.php", function() {
17 ok( $('#first').text() == 'ERROR', 'Check if load works without callback');
22 test("load(String, Object, Function) - check scripts", function() {
25 window.foobar = undefined;
26 window.foo = undefined;
27 var verifyEvaluation = function() {
28 ok( foobar == "bar", 'Check if script src was evaluated after load' );
29 ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM');
30 ok( $('#ap').html() == 'bar', 'Check if script evaluation has modified DOM');
33 $('#first').load('data/test.html', function() {
34 ok( $('#first').html().match(/^html text/), 'Check content after loading html' );
35 ok( foo == "foo", 'Check if script was evaluated after load' );
36 setTimeout(verifyEvaluation, 600);
40 test("serialize()", function() {
42 var data = $(':input').not('button').serialize();
43 // ignore button, IE takes text content as value, not relevant for this test
44 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' );
47 test("test global handlers - success", function() {
50 var counter = { complete: 0, success: 0, error: 0 },
51 success = function() { counter.success++ },
52 error = function() { counter.error++ },
53 complete = function() { counter.complete++ };
55 $('#foo').ajaxStart(complete).ajaxStop(complete).ajaxComplete(complete).ajaxError(error).ajaxSuccess(success);
56 // start with successful test
57 $.ajax({url: "data/name.php", success: success, error: error, complete: function() {
58 ok( counter.error == 0, 'Check succesful request' );
59 ok( counter.success == 2, 'Check succesful request' );
60 ok( counter.complete == 3, 'Check succesful request' );
61 counter.error = counter.success = counter.complete = 0;
63 $.ajax({url: "data/name.php?wait=5", success: success, error: error, complete: function() {
64 ok( counter.error == 2, 'Check failed request' );
65 ok( counter.success == 0, 'Check failed request' );
66 ok( counter.complete == 3, 'Check failed request' );
72 test("test global handlers - failure", function() {
75 var counter = { complete: 0, success: 0, error: 0 },
76 success = function() { counter.success++ },
77 error = function() { counter.error++ };
79 $.ajax({url: "data/name.php", global: false, success: success, error: error, complete: function() {
80 ok( counter.error == 0, 'Check sucesful request without globals' );
81 ok( counter.success == 1, 'Check sucesful request without globals' );
82 ok( counter.complete == 0, 'Check sucesful request without globals' );
83 counter.error = counter.success = counter.complete = 0;
85 $.ajax({url: "data/name.php?wait=5", global: false, success: success, error: error, complete: function() {
86 ok( counter.error == 1, 'Check failed request without globals' );
87 ok( counter.success == 0, 'Check failed request without globals' );
88 ok( counter.complete == 0, 'Check failed request without globals' );
94 test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
97 $.get('data/dashboard.xml', function(xml) {
99 $('tab', xml).each(function() {
100 content.push($(this).text());
102 ok( content[0] == 'blabla', 'Check first tab');
103 ok( content[1] == 'blublu', 'Check second tab');
108 test("$.getIfModified(String, Hash, Function)", function() {
111 $.getIfModified("data/name.php", function(msg) {
112 ok( msg == 'ERROR', 'Check ifModified' );
117 test("$.getScript(String, Function) - with callback", function() {
120 $.getScript("data/test.js", function() {
121 ok( foobar == "bar", 'Check if script was evaluated' );
122 setTimeout(start, 100);
126 test("$.getScript(String, Function) - no callback", function() {
129 $.getScript("data/test.js");
132 test("$.getJSON(String, Hash, Function) - JSON array", function() {
135 $.getJSON("data/json.php", {json: "array"}, function(json) {
136 ok( json[0].name == 'John', 'Check JSON: first, name' );
137 ok( json[0].age == 21, 'Check JSON: first, age' );
138 ok( json[1].name == 'Peter', 'Check JSON: second, name' );
139 ok( json[1].age == 25, 'Check JSON: second, age' );
144 test("$.getJSON(String, Hash, Function) - JSON object", function() {
147 $.getJSON("data/json.php", function(json) {
148 ok( json.data.lang == 'en', 'Check JSON: lang' );
149 ok( json.data.length == 25, 'Check JSON: length' );
154 test("$.post(String, Hash, Function) - simple with xml", function() {
157 $.post("data/name.php", {xml: "5-2"}, function(xml){
158 $('math', xml).each(function() {
159 ok( $('calculation', this).text() == '5-2', 'Check for XML' );
160 ok( $('result', this).text() == '3', 'Check for XML' );
166 test("$.ajaxTimeout(Number) - with global timeout", function() {
171 var pass = function() {
174 ok( true, 'Check local and global callbacks after timeout' );
175 clearTimeout(timeout);
176 $('#main').unbind("ajaxError");
180 var fail = function() {
181 ok( false, 'Check for timeout failed' );
184 timeout = setTimeout(fail, 1500);
185 $('#main').ajaxError(pass);
188 url: "data/name.php?wait=5",
194 test("$.ajaxTimeout(Number) with localtimeout", function() {
195 stop(); $.ajaxTimeout(50);
199 url: "data/name.php?wait=1",
201 ok( false, 'Check for local timeout failed' );
204 success: function() {
205 ok( true, 'Check for local timeout' );
213 test("$.ajax - simple get", function() {
218 url: "data/name.php?name=foo",
219 success: function(msg){
220 ok( msg == 'bar', 'Check for GET' );
226 test("$.ajax - simple post", function() {
231 url: "data/name.php",
233 success: function(msg){
234 ok( msg == 'pan', 'Check for POST' );
240 test("$.ajax - dataType html", function() {
243 window.foobar = undefined;
244 window.foo = undefined;
245 var verifyEvaluation = function() {
246 ok( foobar == "bar", 'Check if script src was evaluated for datatype html' );
251 url: "data/test.html",
252 success: function(data) {
253 ok( data.match(/^html text/), 'Check content for datatype html' );
254 ok( foo == "foo", 'Check if script was evaluated for datatype html' );
255 setTimeout(verifyEvaluation, 600);
260 test("$.ajax - xml: non-namespace elements inside namespaced elements", function() {
264 url: "data/with_fries.xml", dataType: "xml", type: "GET", data: "", success: function(resp) {
265 ok( $("properties", resp).length == 1, 'properties in responseXML' );
266 ok( $("jsconf", resp).length == 1, 'jsconf in responseXML' );
267 ok( $("thing", resp).length == 2, 'things in responseXML' );