How to use xmlhttprequest - 10 common examples

To help you get started, we’ve selected a few xmlhttprequest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OmarElGabry / Hashtegny / node_modules / codebird / codebird.js View on Github external
} catch (e) {
                console.error("ActiveXObject object not defined.");
            }
        // now, consider RequireJS and/or Node.js objects
        } else if (typeof require === "function"
            && require
        ) {
            // look for xmlhttprequest module
            try {
                var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
                xml = new XMLHttpRequest();
            } catch (e1) {
                // or maybe the user is using xhr2
                try {
                    var XMLHttpRequest = require("xhr2");
                    xml = new XMLHttpRequest();
                } catch (e2) {
                    console.error("xhr2 object not defined, cancelling.");
                }
            }
        }
        return xml;
    };
github CyberMiles / tim-research / reading_event_logs / code / nodeJsHtml / app / server.js View on Github external
function getRequestWithOnlyUrl(theUrl) {
    theRequest = new XMLHttpRequest();
    theUrl = theUrl;
    console.log("Checking URL: " + theUrl);
    theRequest.open('GET', theUrl, /* async = */ false);
    theRequest.send();
    if (theRequest.status >= 200 && theRequest.status < 300) {
        return theRequest.responseText;
    } else {
        console.log(theRequest.status);
    }
}
github donejs / done-ssr / lib / polyfills / xhr.js View on Github external
var XHR = global.XMLHttpRequest = function() {
	xhr.apply(this, arguments);
	this._hackSend = this.send;
	this.send = XHR.prototype.send;

	this._hackOpen = this.open;
	this.open = XHR.prototype.open;

	// In browsers these default to null
	this.onload = null;
	this.onerror = null;

	// jQuery checks for this property to see if XHR supports CORS
	this.withCredentials = true;
};
github blengerich / GenAMap / src / frontend / GDCdata / script / GetMarkerData.js View on Github external
function FPKMDownload(line){
    const FPKMPath = path.join(folderPath, 'FPKM')
    mkdirp.sync(FPKMPath)
    const UUID = line.split(' ')[1]
    const caseid = line.split(' ')[0]
    const filepath = path.join(FPKMPath, 'FPKM_'+caseid+'.csv')
    var options = null
    var link = 'https://gdc-api.nci.nih.gov/data/' + UUID
    var suffix
    var filename
    var client = new XMLHttpRequest()
    try{
    client.open("GET", link , true)
    client.send()
    client.onreadystatechange = function() {
      if(this.readyState == 4 && this.status == 200) {
        try{
          var markerStream = fs.createWriteStream(filepath, {'flags':'w'})
          var stream = request(link).pipe(zlib.createGunzip()).pipe(markerStream)
          stream.on('finish', function() {
              markerStream.end()
              FPKM_index = FPKM_index + 1
              console.log('F_'+FPKM_index)
              if(FPKM_index < FPKM_list.length){FPKMDownload(FPKM_list[FPKM_index])}
          })
        }
        catch(err){
github donejs / done-ssr / lib / middleware / xhr.js View on Github external
var XHR = global.XMLHttpRequest = function() {
		xhr.apply(this, arguments);
		this._hackSend = this.send;
		this.send = XHR.prototype.send;

		var oldOpen = this.open;
		this.open = function() {
			var req = global.doneSsr.request;
			var baseUri = req.url || "";
			if ( req.protocol && req.get ) {
				baseUri = req.protocol + '://' + req.get( "host" ) + baseUri;
			}
			var args = Array.prototype.slice.call(arguments);
			var reqURL = args[1];

			if ( reqURL && !fullUrl.test( reqURL ) ) {
				args[1] = url.resolve( baseUri, reqURL );
			}
github Esri / geoservices-js / lib / request.js View on Github external
function get (url, callback) {
  var httpRequest = new XMLHttpRequest();

  httpRequest.onreadystatechange = _requestHandler(callback);

  httpRequest.open("GET", url);
  _maybeSetReferer(httpRequest);
  httpRequest.send(null);
}
github jondubois / nombo / node_modules / socket.io-client / lib / util.js View on Github external
util.ua.hasCORS = 'undefined' != typeof XMLHttpRequest && (function () {
    try {
      var a = new XMLHttpRequest();
    } catch (e) {
      return false;
    }

    return a.withCredentials != undefined;
  })();
github eerotal / LibreSignage / src / node_modules / ls-api / api.js View on Github external
return new Promise((resolve, reject) => {
			let req = new XMLHttpRequest();
			let conf = {
				'ctype': null,
				'data': null,
				'url': `${this.config.host ? this.config.host + '/' : ''}`
						+ `${endpoint.uri}`
			};

			req.addEventListener("load", function() {
				let tmp = null;
				switch(this.getResponseHeader('Content-Type')) {
					case 'application/json':
						tmp = JSON.parse(this.responseText);
						if (tmp.error) {
							reject(new APIError(tmp));
						} else {
							resolve(tmp);
github Esri / geoservices-js / lib / request.js View on Github external
function post (url, data, callback) {
  var httpRequest = new XMLHttpRequest();

  httpRequest.onreadystatechange = _requestHandler(callback);

  httpRequest.open("POST", url);
  _maybeSetReferer(httpRequest);
  httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  httpRequest.send(stringify(data));
}
github twilio / twilio-video.js / lib / request.js View on Github external
return new Promise(function(resolve, reject) {
    if (typeof method !== 'string' || !params) {
      throw new Error('method and params are required args.');
    }

    var xhr = new XHR();
    xhr.open(method.toUpperCase(), params.url, true);
    xhr.withCredentials = !!params.withCredentials;

    xhr.onreadystatechange = function onreadystatechange() {
      if (xhr.readyState !== 4) { return; }

      if (200 <= xhr.status && xhr.status < 300) {
        resolve(xhr.responseText);
      } else {
        reject(xhr.responseText);
      }
    };

    for (var headerName in params.headers) {
      xhr.setRequestHeader(headerName, params.headers[headerName]);
    }

xmlhttprequest

XMLHttpRequest for Node

MIT
Latest version published 9 years ago

Package Health Score

69 / 100
Full package analysis