-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.js
More file actions
42 lines (37 loc) · 1.23 KB
/
tools.js
File metadata and controls
42 lines (37 loc) · 1.23 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
// runRequest executes a json request on PTV xServer internet,
// given the url endpoint, the token and the callbacks to be called
// upon completion. The error callback is parameterless, the success
// callback is called with the object returned by the server.
var runRequest = function (url, request, token, handleSuccess, handleError) {
$.ajax({
url: url,
type: 'POST',
data: JSON.stringify(request),
headers: function () {
var h = {
'Content-Type': 'application/json'
};
if (token) h['Authorization'] = 'Basic ' + btoa('xtok:' + token);
return h;
}(),
success: function (data, status, xhr) {
handleSuccess(data);
},
error: function (xhr, status, error) {
handleError(xhr);
}
});
};
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}