-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtask_status.html
More file actions
117 lines (106 loc) · 3.71 KB
/
task_status.html
File metadata and controls
117 lines (106 loc) · 3.71 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Qencode - Get task status</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<h2><a href="https://cloud.qencode.com">Qencode</a> Get task status example:</h2>
<div>Status url</div>
<div>
<input type="text" id="status_url" class="form-element" value="https://api.qencode.com/v1/status" size="70"/>
</div>
<div>Task token</div>
<div>
<input type="text" id="task_token" class="form-element" size="70"/>
</div>
<div>
<button id="btn_ok" class="form-element">OK</button>
</div>
<hr>
<pre id="status"></pre>
</body>
<script>
var status_url = $('#status_url').val(); //initial url to get status
var call_server = function (url, data, error_text, is_get, send_files) {
var request_type = is_get === true ? 'GET' : 'POST';
data = data === undefined ? {} : data;
if (error_text === undefined) {
error_text = 'error execute ' + url;
}
var request = {
url: url,
type: request_type,
data: data,
dataType: 'json',
crossDomain: true,
async: false,
error : function(jqXHR, exception) {
if (jqXHR.status === 0) {
console.log('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
console.log('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
console.log('Internal Server Error [500].');
} else if (exception === 'parsererror') {
console.log('Requested JSON parse failed.');
} else if (exception === 'timeout') {
console.log('Time out error.');
} else if (exception === 'abort') {
console.log('Ajax request aborted.');
} else {
console.log('Uncaught Error.\n' + jqXHR.responseText);
}
}
};
if (request_type == 'POST' && send_files) {
request.processData = false;
request.contentType = false;
request.cache = false;
}
var res = $.ajax(request);
var response = null;
try {
response = $.parseJSON(res.responseText);
if (!response) {
response = {
'error': false,
'message': error_text
};
}
}
catch (err) {
response = {
'error': true,
'message': error_text + '\n' +
'Error description: ' + err.message + '\n'
};
// response.message += '\n' + res.responseText;
}
return response;
};
var call_server_post = function (url, data, error_text, send_files) {
return call_server(url, data, error_text, false, send_files);
};
function get_status(url, tokens) {
var data = new FormData();
data.append('task_tokens', tokens);
return call_server_post(url, data, null, true);
}
$("#btn_ok").click(
function () {
var task_token = $('#task_token').val();
if (task_token != '') {
var response = get_status(status_url, [task_token]);
var status = response['statuses'][task_token];
$('#status').text(JSON.stringify(status, null, 4));
status_url = status['status_url'];
if (status_url) {
$('#status_url').val(status_url);
}
}
}
);
</script>
</html>