當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript XMLHttpRequest.send方法代碼示例

本文整理匯總了TypeScript中@ephox/sand.XMLHttpRequest.send方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript XMLHttpRequest.send方法的具體用法?TypeScript XMLHttpRequest.send怎麽用?TypeScript XMLHttpRequest.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@ephox/sand.XMLHttpRequest的用法示例。


在下文中一共展示了XMLHttpRequest.send方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: function

      }

      if (settings.content_type) {
        xhr.setRequestHeader('Content-Type', settings.content_type);
      }

      if (settings.requestheaders) {
        Tools.each(settings.requestheaders, function (header) {
          xhr.setRequestHeader(header.key, header.value);
        });
      }

      xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

      xhr = XHR.fire('beforeSend', { xhr, settings }).xhr;
      xhr.send(settings.data);

      // Syncronous request
      if (!settings.async) {
        return ready();
      }

      // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
      setTimeout(ready, 10);
    }
  }
};

Tools.extend(XHR, Observable);

export default XHR;
開發者ID:abstask,項目名稱:tinymce,代碼行數:31,代碼來源:XHR.ts


注:本文中的@ephox/sand.XMLHttpRequest.send方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。