Bonjour,
J'essaye de faire un appel ajax via JQuery avec le code suivant :
Dans dashboard.js, la fonctionque j'utilise est celle là :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Web Interface Monitoring - Theme design by Eduardo L. Arana</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Language" content="en" /> <meta name="robots" content="noindex, nofollow" /> <meta name="author" content="Eduardo L. Arana - info@arananet.net"/> <link rel="stylesheet" type="text/css" href="stylesheets/interface/common.css" media="screen, projection" /> <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" /> <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script type="text/javascript" src="/dbeta/js/dashboard.js"></script> <script type="text/javascript" src="js/mootools.js"></script> <script type="text/javascript" src="js/search.js"></script> </head> <body onload="chargeDashboard();"> <div id="navigation"> <div id="search_box"> <form action="/nagios/cgi-bin/status.cgi" method="get" target="main"> <input id="search" name="host" type="text" /> <input type="hidden" name="navbarsearch" value="1" /> <input src="images/icons/search.png" width="20" height="20" alt="OK" title="Search" id="search_submit" type="image" /> </form> </div> </div> </body> </html> <script> function init(){ $.ajax({ type: 'POST', url: 'loadGraph.php', dataType:'JSON', success: function(data) { console.debug(data); var arr = $.map(data, function(el) { return el; }); console.debug(arr); for(var i = 0; i <= arr.length - 2; i++){ } updatePosition(id); }, complete : function(resultat, statut){ } }); } var availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ]; $( "#search" ).autocomplete({ source: availableTags }); </script>
Je sais que le code n'est pas du tout adapté, c'est juste que j'ai copié collé suite à l'ajax ne marchant pas sur une page, alors qu'il fonctionne très bien sur une autre. Et j'en tient pour preuv eque la fonction que j'essaye d'utiliser marche très bien là dessus :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 function chargeDashboard(){ console.log("[DASHBOARD DL] Started the Dashboard load phase") $.ajax({ type: 'POST', url: 'getDashboard.php', data: {"user_id" : 1}, dataType:'JSON', success: function(data) { console.log(data); var arr = $.map(data, function(el) { return el; }); for(var i = 0; i <= arr.length - 2; i++){ $('.onglets').append("<span class='onglet_0 onglet' id='onglet_dashboard_"+arr[i]['id']+"' onclick='change_onglet(\"dashboard_"+arr[i]['id']+"\");' >"+arr[i]["nom"]+"</span>"); $(".contenu_onglets").append("<div class='dashboard' id='contenu_onglet_dashboard_"+arr[i]['id']+"' style='display: none;' data-toggle='context' data-target='#context-menu'>"); $(".contenu_onglets").append("</div>"); $('.contenu_onglets > #contenu_onglet_dashboard_'+arr[i]["id"]).append('<input type="hidden" value="'+arr[i]["id"]+'" id="dashboardId">'); chargeWidget(arr[i]['id']) if(typeof anc_onglet == "undefined"){ anc_onglet = "dashboard_"+arr[i]['id'] } } $('.onglets').append("<span class='onglet_0 onglet' id='onglet_dashboard_add' onclick='overlayDashboard()');' style='width: 30px; text-align : center'>+</span>"); }, complete: function(a,b){ change_onglet(anc_onglet); } }); $('#freeze').hide(); $('#stopDelete').hide(); $('#stopDashDelete').hide(); }
J'ai importé les mêmes librairies comme vous pouvez le constatez. Mais cette fois j'ai ce message d'erreur de la console :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 <html> <head> <title>Dashboard</title> <meta charset="utf-8" /> <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script type="text/javascript" src="/dbeta/js/dashboard.js"></script> <script type="text/javascript" src="/dbeta/js/contextMenu.js"></script> <link rel="stylesheet" type="text/css" href="/nagios/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="/dbeta/css/contextMenu.css"> <style> #bodyOverlayed{ background-color: #a1a1a1; } .dashboard{ width: 92%; height: 100%; border : 1px solid black; } #dashboard_menu{ display: inline; } #info{ position: fixed; top: 0; left: 92%; } .widget{ position : absolute; padding: 3px; border: 1px solid black; transition : 500ms easeout; } .widget:hover{ border: 2px dotted #00F; } #widget1{ width: 500px; height: 200px; background-color: transparent; } .xpos{ display: inline; } .ypos{ display: inline; } #draggable { width: 150px; height: 150px; padding: 0.5em; } .ui-resizable-helper { border: 2px dotted #00F; } .widget_title{ font-size: 12px; font-weight : bold; } .removed{ display: none; } .menuB{ width: 65%; margin: 3px; } #info{ border : 1px solid brown; padding: 3px; margin: 3px; } #overlay { visibility: hidden; position: absolute; left: 0px; top: 0px; width:100%; height:100%; text-align:center; z-index: 1000; } .popupContent{ width:300px; margin: 100px auto; background-color: #fff; border:1px solid #000; padding:15px; text-align:center; } .onglet { display:inline-block; margin-left:3px; margin-right:3px; padding:3px; border:1px solid black; cursor:pointer; border-top-left-radius: 20px; border-top-right-radius: 20px; color: white; font-weight : bold; transition: 200ms; } .onglet_0 { background:#474747; border-bottom:1px solid black; z-index: 0; } .onglet_0:hover{ background:#737373; border: 1px solid yellow; } .onglet_0:active{ z-index: 50; } .onglet_1:focus{ z-index: 25; } .onglet_1 { background:#737373; border-bottom:0px solid black; padding-bottom:4px; z-index: 25; } .onglet_1:hover { border: 1px solid yellow; } .contenu_onglet { background-color:#dddddd; border:1px solid black; margin-top:-1px; padding:5px; display:none; margin-left: 10px; margin-right: 10px; } </style> </head> <body onload="chargeDashboard();"> <?php try { $bdd = new PDO('mysql:host=172.16.1.39;dbname=dashboard;charset=utf8', 'nagioscfg', 'nagioscfgpass76'); } catch (Exception $e) { die('Erreur : ' . $e->getMessage()); } ?> <div id="info"> <div id="positions"> </div> </div> <div id="overlay"> <div class="popupContent"> <a href='#' onclick='overlay()'>X</a> <div id="addWidget"> </div> </div> </div> <div class="systeme_onglets"> <div class="onglets"> </div> <div class="contenu_onglets"> </div> </div> <div id="dashboard_menu"> </div> <div id="context-menu"> <ul class="dropdown-menu" role="menu"> <li id="addingWidget"><a tabindex="-1" href="javascript:void(0)" onclick="overlay();">Add a new widget</a></li> <li id="change"><a tabindex="-1" href="javascript:void(0)" onclick="setAllWidget()">Modify position</a></li> <li id="freeze"><a tabindex="-1" href="javascript:void(0)" onclick="unsetAllWidget(); save();">Stop and save modification</a></li> <li id="delete"><a tabindex="-1" href="javascript:void(0)" onclick="setAllWidgetForDelete();">Start Widget Delete mode</a></li> <li id="stopDelete"><a tabindex="-1" href="javascript:void(0)" onclick="unsetAllWidgetForDelete();">Stop Widget Delete mode</a></li> <li id="dashDelete"><a tabindex="-1" href="javascript:void(0)" onclick="setDashboardForDelete();">Start Dashboard DeleteOnClick mode</a></li> <li id="stopDashDelete"><a tabindex="-1" href="javascript:void(0)" onclick="unsetDashboardForDelete();">Stop Dashboard DeleteOnClick mode</a></li> </ul> </div> </body> <script type="text/javascript"> //<!-- var anc_onglet; function menu(id){ if(id == 1){ overlay(); }else if(id == 2){ setAllWidget() }else if(id == 3){ setAllWidgetForDelete(); } } function change_onglet(name) { if(typeof anc_onglet == "undefined"){ document.getElementById('onglet_'+name).className = 'onglet_1 onglet'; $('.dashboard').each.style.display = 'none'; document.getElementById('contenu_onglet_'+name).style.display = 'block'; anc_onglet = name; } else { document.getElementById('onglet_'+anc_onglet).className = 'onglet_0 onglet'; document.getElementById('onglet_'+name).className = 'onglet_1 onglet'; document.getElementById('contenu_onglet_'+anc_onglet).style.display = 'none'; document.getElementById('contenu_onglet_'+name).style.display = 'block'; anc_onglet = name; var id = name.split("_"); console.log("Opened tab : "+id[1]) updatePosition(id[1]); } } </script> </html>
Que faire donc ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 Uncaught TypeError: $.ajax is not a function chargeDashboard @ dashboard.js:25 onload @ sidebar.html:18
Merçi d'avance
Partager