webservice.js revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 5webservice = new (function() { 6 7this.AJAX_BASE_URL_ = '/ajax'; 8 9this.ajaxRequest = function(path, responseCallback, errorCallback, postArgs) { 10 var reqType = postArgs ? 'POST' : 'GET'; 11 var reqData = postArgs ? JSON.stringify(postArgs) : ''; 12 13 $.ajax({ 14 url: this.AJAX_BASE_URL_ + path, 15 type: reqType, 16 data: reqData, 17 success: responseCallback, 18 dataType: 'json', 19 error: function (xhr, ajaxOptions, thrownError) { 20 console.log('------------------------'); 21 console.log('AJAX error (req: ' + path + ').'); 22 console.log('HTTP response: ' + xhr.status + ' ' + thrownError); 23 console.log(xhr.responseText); 24 if (errorCallback) 25 errorCallback(xhr.status, xhr.responseText); 26 } 27 }); 28}; 29 30})();