PageSourceSearch

https://uptoyoueducacion.com/wp-content/plugins/packlink-pro-shipp…/packlink/js/AjaxService.js?ver=4.4.3

js uptoyoueducacion.com collected 2026-10-05 05:45:03 UTC 4,285 bytes, 139 lines download raw bytes

1if (!window.Packlink) {
2    window.Packlink = {};
3}
4
5(function () {
6    /**
7     * Ajax service. Methods are make public so that they could be overridden in the integrations that
8     * require different mechanisms for AJAX requests.
9     *
10     * @constructor
11     */
12    function AjaxService() {
13        /**
14         * Performs GET ajax request.
15         *
16         * @param {string} url
17         * @param {function} [onSuccess]
18         * @param {function} [onError]
19         */
20        this.get = function (url, onSuccess, onError) {
21            this.call('GET', url, {}, onSuccess, onError);
22        };
23
24        /**
25         * Performs POST ajax request.
26         *
27         * @note You can not post data that has fields with special values such as infinity, undefined etc.
28         *
29         * @param {string} url
30         * @param {object} data
31         * @param {function} [onSuccess]
32         * @param {function} [onError]
33         */
34        this.post = function (url, data, onSuccess, onError) {
35            this.call('POST', url, data, onSuccess, onError);
36        };
37
38        /**
39         * Performs ajax call.
40         *
41         * @param {string} method 'GET' or 'POST'.
42         * @param {string} url
43         * @param {object} data
44         * @param {function} [onSuccess]
45         * @param {function} [onError]
46         */
47        this.call = function (method, url, data, onSuccess, onError) {
48            const request = getRequest();
49            const callUUID = Packlink.StateUUIDService.getStateUUID();
50
51            if (!onError) {
52                onError = Packlink.responseService.errorHandler;
53            }
54
55            url = url.replace('https:', '');
56            url = url.replace('http:', '');
57
58            request.open(method, url, true);
59
60            request.onreadystatechange = function () {
61                // "this" is XMLHttpRequest
62                if (this.readyState === 4) {
63                    if (callUUID !== Packlink.StateUUIDService.getStateUUID()) {
64                        // Obsolete response. The app has changed the original state that issued the call.
65
66                        return;
67                    }
68
69                    if (this.status >= 200 && this.status < 300) {
70                        if (onSuccess) {
71                            onSuccess(JSON.parse(this.responseText || '{}'));
72                        }
73                    } else if (onError) {
74                        let response = this.responseText;
75                        try {
76                            response = JSON.parse(this.responseText || '{}');
77                        } catch (e) {
78                        }
79
80                        onError(response);
81
82                    }
83                }
84            };
85
86            request.setRequestHeader('Accept', 'application/json');
87
88            if (method === 'POST') {
89                this.internalPerformPost(request, data);
90            } else {
91                request.send();
92            }
93        };
94
95        /**
96         * Extension point for executing the POST request with the given data.
97         *
98         * @param {XMLHttpRequest | ActiveXObject} request
99         * @param {object} data
100         */
101        this.internalPerformPost = function (request, data) {
102            request.setRequestHeader('Content-Type', 'application/json');
103            request.send(JSON.stringify(data));
104        };
105
106        /**
107         * Creates instance of request.
108         *
109         * @return {XMLHttpRequest | ActiveXObject}
110         */
111        function getRequest() {
112            let versions = [
113                    'MSXML2.XmlHttp.6.0',
114                    'MSXML2.XmlHttp.5.0',
115                    'MSXML2.XmlHttp.4.0',
116                    'MSXML2.XmlHttp.3.0',
117                    'MSXML2.XmlHttp.2.0',
118                    'Microsoft.XmlHttp'
119                ],
120                xhr;
121
122            if (typeof XMLHttpRequest !== 'undefined') {
123                return new XMLHttpRequest();
124            }
125
126            for (let version of versions) {
127                try {
128                    xhr = new ActiveXObject(version);
129                    break;
130                } catch (e) {
131                }
132            }
133
134            return xhr;
135        }
136    }
137
138    Packlink.ajaxService = new AjaxService();
139})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.