当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript sand.XMLHttpRequest类代码示例

本文整理汇总了TypeScript中@ephox/sand.XMLHttpRequest的典型用法代码示例。如果您正苦于以下问题:TypeScript XMLHttpRequest类的具体用法?TypeScript XMLHttpRequest怎么用?TypeScript XMLHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XMLHttpRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Promise

  return new Promise(function (resolve, reject) {

    const rejectWithError = function () {
      reject('Cannot convert ' + url + ' to Blob. Resource might not exist or is inaccessible.');
    };

    try {
      const xhr = new XMLHttpRequest();

      xhr.open('GET', url, true);
      xhr.responseType = 'blob';

      xhr.onload = function () {
        if (this.status === 200) {
          resolve(this.response);
        } else {
          // IE11 makes it into onload but responds with status 500
          rejectWithError();
        }
      };

      // Chrome fires an error event instead of the exception
      // Also there seems to be no way to intercept the message that is logged to the console
      xhr.onerror = rejectWithError;

      xhr.send();
    } catch (ex) {
      rejectWithError();
    }
  });
开发者ID:aha-app,项目名称:tinymce-word-paste-filter,代码行数:30,代码来源:Conversions.ts

示例2: function

  const defaultHandler = function (blobInfo, success, failure, progress) {
    let xhr, formData;

    xhr = new XMLHttpRequest();
    xhr.open('POST', settings.url);
    xhr.withCredentials = settings.credentials;

    xhr.upload.onprogress = function (e) {
      progress(e.loaded / e.total * 100);
    };

    xhr.onerror = function () {
      failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
    };

    xhr.onload = function () {
      let json;

      if (xhr.status < 200 || xhr.status >= 300) {
        failure('HTTP Error: ' + xhr.status);
        return;
      }

      json = JSON.parse(xhr.responseText);

      if (!json || typeof json.location !== 'string') {
        failure('Invalid JSON: ' + xhr.responseText);
        return;
      }

      success(pathJoin(settings.basePath, json.location));
    };

    formData = new FormData(); // TODO: Stick this in sand
    formData.append('file', blobInfo.blob(), blobInfo.filename());

    xhr.send(formData);
  };
开发者ID:abstask,项目名称:tinymce,代码行数:38,代码来源:Uploader.ts

示例3: XMLHttpRequest

  return new Promise<{status: number, blob: Blob}>(function (resolve) {
    let xhr;

    xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
        resolve({
          status: xhr.status,
          blob: this.response
        });
      }
    };

    xhr.open('GET', url, true);

    Tools.each(headers, function (value, key) {
      xhr.setRequestHeader(key, value);
    });

    xhr.responseType = 'blob';
    xhr.send();
  });
开发者ID:abstask,项目名称:tinymce,代码行数:23,代码来源:Utils.ts

示例4: setTimeout

        xhr = null;
      } else {
        setTimeout(ready, 10);
      }
    };

    // Default settings
    settings.scope = settings.scope || this;
    settings.success_scope = settings.success_scope || settings.scope;
    settings.error_scope = settings.error_scope || settings.scope;
    settings.async = settings.async === false ? false : true;
    settings.data = settings.data || '';

    XHR.fire('beforeInitialize', { settings });

    xhr = new XMLHttpRequest();

    if (xhr) {
      if (xhr.overrideMimeType) {
        xhr.overrideMimeType(settings.content_type);
      }

      xhr.open(settings.type || (settings.data ? 'POST' : 'GET'), settings.url, settings.async);

      if (settings.crossDomain) {
        xhr.withCredentials = true;
      }

      if (settings.content_type) {
        xhr.setRequestHeader('Content-Type', settings.content_type);
      }
开发者ID:abstask,项目名称:tinymce,代码行数:31,代码来源:XHR.ts

示例5: function

 Tools.each(headers, function (value, key) {
   xhr.setRequestHeader(key, value);
 });
开发者ID:abstask,项目名称:tinymce,代码行数:3,代码来源:Utils.ts


注:本文中的@ephox/sand.XMLHttpRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。