-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathajax_requests.js
71 lines (50 loc) · 1.42 KB
/
ajax_requests.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
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
(function ($) {
// Expressions indented
console.log(gdprwp);
var form;
var formData;
$(document).on('submit', '#gdpr-export-form', function (e) {
e.preventDefault();
form = $(this);
formData = new FormData(this);
console.log(formData);
var type = form.attr('method');
start_export(form, type);
});
var start_export = function (form, type) {
console.log('started export');
show_spinner();
$.ajax({
url: gdprwp.endpoints.getdata,
method: type,
processData: false,
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', gdprwp.nonce );
},
data: form.serialize(),
// data: data,
dataType: 'json',
// cache: false,
// contentType: false,
}).done(function (response) {
console.log(response);
// var amount = $('<p />').appendTo('#response');
// amount.text(response.data.length + ' items found');
print_container_data(response.gdpr_container);
}).fail(function (response) {
console.log('Error');
// var div = $('<p />').appendTo('#response');
// success.text('Error! Something went wrong.');
}).always(function (response) {
hide_spinner();
})
}
var print_container_data = function ( $gdpr_container ) {
}
function show_spinner() {
$('.spinner').css('visibility', 'visible');
}
function hide_spinner() {
$('.spinner').css('visibility', 'hidden');
}
})(jQuery);