/**
 * Class with helper methods to handle asynchronous JavaScript requests
 */ export class AJAX { param url returns { any } public static ajax ( url , timeout = 9000 ) { let xhttp ; const mimeType = url . indexOf ( ".mxl" ) > - 1 ? "text/plain; charset=x-user-defined" : "application/xml" ; if ( XMLHttpRequest ) { xhttp = new XMLHttpRequest ( ) ; } else if ( ActiveXObject ) { xhttp = new ActiveXObject ( "Microsoft.XMLHTTP" ) ; } else { return Promise . reject ( new Error ( "XMLHttp not supported." ) ) ; } xhttp . timeout = timeout ; return new Promise ( ( resolve , reject ) => { xhttp . onreadystatechange = ( ) : void => { if ( xhttp . readyState === XMLHttpRequest . DONE ) { if ( xhttp . status === 200 ) { resolve ( xhttp . responseText ) ; } else if ( xhttp . status === 0 && xhttp . responseText ) { resolve ( xhttp . responseText ) ; } else { reject ( new Error ( "Could not retrieve requested URL " + xhttp . status ) ) ; } } } ; xhttp . ontimeout = ( e ) : void => { reject ( new Error ( "Server request Timeout" ) ) ; } ; xhttp . overrideMimeType ( mimeType ) ; xhttp . open ( "GET" , url , true ) ; xhttp . send ( ) ; } ) ; } }