Repository navigation
Expand file tree
/
Copy pathWebIQ_Sample_script
More file actions
47 lines (42 loc) · 2.1 KB
/
Copy pathWebIQ_Sample_script
File metadata and controls
47 lines (42 loc) · 2.1 KB
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
/*
* Replace YOUR_LOG_SERVER_IP and YOUR_NJSERVER_LOG_API_KEY before use.
* The WebIQ page origin must also be in NJSERVER_LOG_ALLOWED_ORIGINS on the log server.
* First "create entry" in "code manager" (Alt+C), Local-Scripts, and name it whatever you like.
* Then add code below after the comment " //Place your Code here "
* Keep in mind that you need to first download and install the lib-jquery3 package with a package manager (Alt+Q)
* For this specific example you need to add a HTML widget with the code below then you have a simple button to click to download the log file
*<body>
*<button id="download-log-button">Download Log</button>
*</body>
*/
$(document).ready(function() {
console.log("Document is ready");
$('#download-log-button').click(function() {
console.log("Button clicked");
$.ajax({
url: 'http://YOUR_LOG_SERVER_IP:3000/download-log', // Use the IP address of your log server
method: 'GET',
headers: {
'X-API-Key': 'YOUR_NJSERVER_LOG_API_KEY'
},
xhrFields: {
responseType: 'blob'
},
success: function(data) {
console.log("AJAX request successful");
const url = window.URL.createObjectURL(data);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'connect.zip';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
},
error: function(jqXHR, textStatus, errorThrown) {
console.error("AJAX request failed: " + textStatus + ", " + errorThrown);
alert('Error downloading the log file.');
}
});
});
});