Debian Codegraph @

old-tests/tests_onhold/3_ajax/fnServerParams.js

raw
1 // DATA_TEMPLATE: empty_table
2 oTest.fnStart( "fnServerParams" );
3
4
5 $(document).ready( function () {
6 /* Check the default */
7 var json = {};
8 var oTable = $('#example').dataTable( {
9 "sAjaxSource": "../data_sources/param.php"
10 } ).on('xhr', function (e, settings, o) {
11 json = o;
12 } );
13
14 oTest.fnWaitTest(
15 "jQuery anti-cache parameter was sent",
16 null,
17 function () {
18 return json.get && json.get._;
19 }
20 );
21
22 oTest.fnWaitTest(
23 "No other parameters sent",
24 null,
25 function () {
26 return 1 === $.map( json.get, function (val) {
27 return val;
28 } ).length;
29 }
30 );
31
32 oTest.fnWaitTest(
33 "Send additional parameters",
34 function () {
35 oSession.fnRestore();
36 json = {};
37
38 $('#example').dataTable( {
39 "sAjaxSource": "../data_sources/param.php",
40 "fnServerParams": function ( data ) {
41 data.push( { name: 'test', value: 'unit' } );
42 }
43 } ).on('xhr', function (e, settings, o) {
44 json = o;
45 } );
46 },
47 function () {
48 return json.get && json.get.test === 'unit';
49 }
50 );
51
52 oTest.fnTest(
53 "jQuery anti-cache parameter was still sent",
54 null,
55 function () {
56 return json.get._;
57 }
58 );
59
60 oTest.fnWaitTest(
61 "Send multiple parameters",
62 function () {
63 oSession.fnRestore();
64 json = {};
65
66 $('#example').dataTable( {
67 "sAjaxSource": "../data_sources/param.php",
68 "fnServerParams": function ( data ) {
69 data.push( { name: 'test', value: 'unit' } );
70 data.push( { name: 'tapestry', value: 'king' } );
71 }
72 } ).on('xhr', function (e, settings, o) {
73 json = o;
74 } );
75 },
76 function () {
77 return json.get && json.get.test === 'unit' && json.get.tapestry === 'king';
78 }
79 );
80
81 oTest.fnComplete();
82 } );