Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / memory_inspector / memory_inspector / frontends / www_content / js / webservice.js
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 webservice = new (function() {
6
7 this.AJAX_BASE_URL_ = '/ajax';
8
9 this.onServerUnreachableOrTimeout = null;
10
11 this.ajaxRequest = function(path, responseCallback, errorCallback, postArgs) {
12   var reqType = postArgs ? 'POST' : 'GET';
13   var reqData = postArgs ? JSON.stringify(postArgs) : '';
14
15   $.ajax({
16     url: this.AJAX_BASE_URL_ + path,
17     type: reqType,
18     data: reqData,
19     success: responseCallback,
20     dataType: 'json',
21     error: function (xhr, ajaxOptions, thrownError) {
22       console.log('------------------------');
23       console.log('AJAX error (req: ' + path + ').');
24       console.log('HTTP response: ' + xhr.status + ' ' + thrownError);
25       console.log(xhr.responseText);
26       if (errorCallback)
27         errorCallback(xhr.status, xhr.responseText);
28       if (xhr.readyState < 4 && this_.onServerUnreachableOrTimeout != null)
29         webservice.onServerUnreachableOrTimeout();
30     }
31   });
32 };
33
34 })();