function loadFeaturesXhr(
  url,
  format,
  extent,
  resolution,
  projection,
  success,
  failure,
) {
  const xhr = new XMLHttpRequest();
  xhr.open(
    'GET',
    typeof url === 'function' ? url(extent, resolution, projection) : url,
    true,
  );
  if (format.getType() == 'arraybuffer') {
    xhr.responseType = 'arraybuffer';
  }
  xhr.withCredentials = withCredentials;
  /**
   * @param {Event} event Event.
   * @private
   */
  xhr.onload = function (event) {
    // status will be 0 for file:// urls
    if (!xhr.status || (xhr.status >= 200 && xhr.status < 300)) {
      const type = format.getType();
      try {
        /** @type {Document|Node|Object|string|undefined} */
        let source;
        if (type == 'text' || type == 'json') {
          source = xhr.responseText;
        } else if (type == 'xml') {
          source = xhr.responseXML || xhr.responseText;
        } else if (type == 'arraybuffer') {
          source = /** @type {ArrayBuffer} */ (xhr.response);
        }
        if (source) {
          success(
            /** @type {Array<FeatureType>} */
            (
              format.readFeatures(source, {
                extent: extent,
                featureProjection: projection,
              })
            ),
            format.readProjection(source),
          );
        } else {
          failure();
        }
      } catch {
        failure();
      }
    } else {
      failure();
    }
  };
  /**
   * @private
   */
  xhr.onerror = failure;
  xhr.send();
}
@template {import("./Feature.js").FeatureLike} [FeatureType=import("./Feature.js").default]
@param {string|FeatureUrlFunction} url Feature URL service.
@param {import("./format/Feature.js").default<FeatureType>} format Feature format.
@param {import("./extent.js").Extent} extent Extent.
@param {number} resolution Resolution.
@param {import("./proj/Projection.js").default} projection Projection.
@param {function(Array<FeatureType>, import("./proj/Projection.js").default): void} success Success
     Function called with the loaded features and optionally with the data projection.
@param {function(): void} failure Failure
     Function called when loading failed.