-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
44 lines (38 loc) · 1.19 KB
/
scripts.js
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
$(document).ready(function(){
$('.commands form').each(function() {
$(this).submit(function(event) {
event.preventDefault();
const $form = $(this);
if (!$form.exists()) {
alert('Le formulaire \'' + formId + '\' n\'existe pas !');
return;
}
$statusWrapper = $('#statusWrapper > p');
$messageWrapper = $('#messageWrapper > p');
$dataWrapper = $('#dataWrapper > pre');
$debugWrapper = $('#debugWrapper > div');
$statusWrapper.html('');
$messageWrapper.html('');
$dataWrapper.html('');
$debugWrapper.html('');
$.ajax({
url : $form.attr('action'),
type : $form.attr('method'),
data : $form.serialize(),
dataType : 'json',
})
.done(function(data, status, request) {
$statusWrapper.html(data.status);
$messageWrapper.html(data.message);
$dataWrapper.html(data.data.replace(new RegExp('<', 'g'), '<'));
$debugWrapper.html(data.debug);
})
.fail(function(request, status, error) {
alert('Error : ' + error);
})
});
});
});
$.fn.exists = function () {
return this.length !== 0;
}