function doRequest(method, url, payload)
{
    return new Promise(function (resolve, reject) {
        var xhr = new XMLHttpRequest();
        xhr.open(method, url);
        xhr.setRequestHeader('Content-Type','application/json');
        xhr.onload = resolve;
        xhr.onerror = reject;
        xhr.send(JSON.stringify(payload));
    })
        .then(
            function onResolve(ret)
            {
                try {
                    // In the happy flow we get a JSON response
                    return JSON.parse(ret.target.response);
                } catch(err) {
                    // HTTP errors (404, 500, etc.) result in text/html
                    return ret.target.response;
                }
            },
            function onReject(err)
            {
                console.log(err);
                console.log("*** Error connecting to RPC port.");
            }
        )
        .catch(console.log); // Catch-all.
}
/**
 * A utility function for communicating via RPC.
 * @param {string} method - HTTP methods such as 'GET', 'POST', 'PATCH', etc.
 * @returns {Promise}
 */
A utility function for communicating via RPC.
A utility function for communicating via RPC .
function doRequest(method, url, payload)
{
    return new Promise(function (resolve, reject) {
        var xhr = new XMLHttpRequest();
        xhr.open(method, url);
        xhr.setRequestHeader('Content-Type','application/json');
        xhr.onload = resolve;
        xhr.onerror = reject;
        xhr.send(JSON.stringify(payload));
    })
        .then(
            function onResolve(ret)
            {
                try {
                    return JSON.parse(ret.target.response);
                } catch(err) {
                    return ret.target.response;
                }
            },
            function onReject(err)
            {
                console.log(err);
                console.log("*** Error connecting to RPC port.");
            }
        )
        .catch(console.log); 
}
function doRequest ( method , url , payload ) { return new Promise ( function ( resolve , reject ) { var xhr = new XMLHttpRequest ( ) ; xhr . open ( method , url ) ; xhr . setRequestHeader ( 'Content-Type' , 'application/json' ) ; xhr . onload = resolve ; xhr . onerror = reject ; xhr . send ( JSON . stringify ( payload ) ) ; } ) . then ( function onResolve ( ret ) { try { return JSON . parse ( ret . target . response ) ; } catch ( err ) { return ret . target . response ; } } , function onReject ( err ) { console . log ( err ) ; console . log ( "*** Error connecting to RPC port." ) ; } ) . catch ( console . log ) ; }
A utility function for communicating via RPC.
A utility function for communicating via RPC .
// In the happy flow we get a JSON response // HTTP errors (404, 500, etc.) result in text/html // Catch-all.