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.
5 webservice = new (function() {
7 this.AJAX_BASE_URL_ = '/ajax';
9 this.onServerUnreachableOrTimeout = null;
11 this.ajaxRequest = function(path, responseCallback, errorCallback, postArgs) {
12 var reqType = postArgs ? 'POST' : 'GET';
13 var reqData = postArgs ? JSON.stringify(postArgs) : '';
16 url: this.AJAX_BASE_URL_ + path,
19 success: responseCallback,
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);
27 errorCallback(xhr.status, xhr.responseText);
28 if (xhr.readyState < 4 && this_.onServerUnreachableOrTimeout != null)
29 webservice.onServerUnreachableOrTimeout();