github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/mist/assets/ext/ethereum.js/lib/httpsync.js (about)

     1  /*
     2      This file is part of ethereum.js.
     3  
     4      ethereum.js is free software: you can redistribute it and/or modify
     5      it under the terms of the GNU Lesser General Public License as published by
     6      the Free Software Foundation, either version 3 of the License, or
     7      (at your option) any later version.
     8  
     9      ethereum.js is distributed in the hope that it will be useful,
    10      but WITHOUT ANY WARRANTY; without even the implied warranty of
    11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12      GNU Lesser General Public License for more details.
    13  
    14      You should have received a copy of the GNU Lesser General Public License
    15      along with ethereum.js.  If not, see <http://www.gnu.org/licenses/>.
    16  */
    17  /** @file httpsync.js
    18   * @authors:
    19   *   Marek Kotewicz <marek@ethdev.com>
    20   *   Marian Oancea <marian@ethdev.com>
    21   * @date 2014
    22   */
    23  
    24  if (process.env.NODE_ENV !== 'build') {
    25          var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
    26  }
    27  
    28  var HttpSyncProvider = function (host) {
    29      this.handlers = [];
    30      this.host = host || 'http://localhost:8080';
    31  };
    32  
    33  HttpSyncProvider.prototype.send = function (payload) {
    34      //var data = formatJsonRpcObject(payload);
    35      
    36      var request = new XMLHttpRequest();
    37      request.open('POST', this.host, false);
    38      request.send(JSON.stringify(payload));
    39      
    40      // check request.status
    41      var result = request.responseText;
    42      return JSON.parse(result);
    43  };
    44  
    45  module.exports = HttpSyncProvider;
    46