ker/mod/tfw.web-service.js
function request( url, args ) {
    return new Promise( function( resolve, reject ) {
        const xhr = new XMLHttpRequest();
        xhr.open( "POST", url, true ); // true is for async.
        xhr.onload = () => {
            const DONE = 4;
            if ( xhr.readyState !== DONE ) return;

            console.info( "xhr.status=", xhr.status );
            console.info( "xhr.responseText=", xhr.responseText );
            if ( xhr.status === 200 ) resolve( xhr.responseText );
            /*
            else reject( {
                id: exports.HTTP_ERROR,
                msg: "(" + xhr.status + ") " + xhr.statusText,
                status: xhr.status
            } );
            */
        };
        xhr.onerror = function() {
            reject( {
                id: exports.HTTP_ERROR,
                err: "HTTP_ERROR (" + xhr.status + ") " + xhr.statusText,
                status: xhr.status
            } );
        };
        const params = Object.keys( args )
            .map( key => `${key}=${encodeURIComponent(args[key])}` )
            .join( "&" );
        xhr.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
        xhr.send( params );
    } );
}
function request( url, args ) {
    return new Promise( function( resolve, reject ) {
        const xhr = new XMLHttpRequest();
        xhr.open( "POST", url, true ); // true is for async.
        xhr.onload = () => {
            const DONE = 4;
            if ( xhr.readyState !== DONE ) return;

            console.info( "xhr.status=", xhr.status );
            console.info( "xhr.responseText=", xhr.responseText );
            if ( xhr.status === 200 ) resolve( xhr.responseText );
            /*
            else reject( {
                id: exports.HTTP_ERROR,
                msg: "(" + xhr.status + ") " + xhr.statusText,
                status: xhr.status
            } );
            */
        };
        xhr.onerror = function() {
            reject( {
                id: exports.HTTP_ERROR,
                err: "HTTP_ERROR (" + xhr.status + ") " + xhr.statusText,
                status: xhr.status
            } );
        };
        const params = Object.keys( args )
            .map( key => `${key}=${encodeURIComponent(args[key])}` )
            .join( "&" );
        xhr.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
        xhr.send( params );
    } );
}
function request ( url , args ) { return new Promise ( function ( resolve , reject ) { const xhr = new XMLHttpRequest ( ) ; xhr . open ( "POST" , url , true ) ; // true is for async. xhr . onload = ( ) => { const DONE = 4 ; if ( xhr . readyState !== DONE ) return ; console . info ( "xhr.status=" , xhr . status ) ; console . info ( "xhr.responseText=" , xhr . responseText ) ; if ( xhr . status === 200 ) resolve ( xhr . responseText ) ; /*
            else reject( {
                id: exports.HTTP_ERROR,
                msg: "(" + xhr.status + ") " + xhr.statusText,
                status: xhr.status
            } );
            */ } ; xhr . onerror = function ( ) { reject ( { id : exports . HTTP_ERROR , err : "HTTP_ERROR (" + xhr . status + ") " + xhr . statusText , status : xhr . status } ) ; } ; const params = Object . keys ( args ) . map ( key => ` ${ key } ${ encodeURIComponent ( args [ key ] ) } ` ) . join ( "&" ) ; xhr . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ; xhr . send ( params ) ; } ) ; }
Request any web server with POST method and returns text.

@param {string} url - URL of the server to request. Can contain GET params.
@param {object} args - Arguments to send with the POST methos.
@returns {Promise} Resolves in the response as string.
Request any web server with POST method and returns text .