com.google.gwt.xhr.client.XMLHttpRequest.send()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中com.google.gwt.xhr.client.XMLHttpRequest.send()方法的一些代码示例,展示了XMLHttpRequest.send()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLHttpRequest.send()方法的具体详情如下:
包路径:com.google.gwt.xhr.client.XMLHttpRequest
类名称:XMLHttpRequest
方法名:send

XMLHttpRequest.send介绍

[英]Initiates a request with no request data. This simply calls #send(String) with null as an argument, because the no-argument send() method is unavailable on Firefox.
[中]启动没有请求数据的请求。这只是调用带有null作为参数的#send(String),因为在Firefox上没有参数send()方法。

代码示例

代码示例来源:origin: libgdx/libgdx

public void loadBinary (final String url, final AssetLoaderListener<Blob> listener) {
  XMLHttpRequest request = XMLHttpRequest.create();        
  request.setOnReadyStateChange(new ReadyStateChangeHandler() {
    @Override
    public void onReadyStateChange (XMLHttpRequest xhr) {
      if (xhr.getReadyState() == XMLHttpRequest.DONE) {
        if (xhr.getStatus() != 200) {
          listener.onFailure();
        } else {
          Int8Array data = TypedArrays.createInt8Array(xhr.getResponseArrayBuffer());
          listener.onSuccess(new Blob(data));
        }
      }
    }
  });
  setOnProgress(request, listener);
  request.open("GET", url);
  request.setResponseType(ResponseType.ArrayBuffer);
  request.send();
}

代码示例来源:origin: libgdx/libgdx

public void loadText (String url, final AssetLoaderListener<String> listener) {
  XMLHttpRequest request = XMLHttpRequest.create();
  request.setOnReadyStateChange(new ReadyStateChangeHandler() {
    @Override
    public void onReadyStateChange (XMLHttpRequest xhr) {
      if (xhr.getReadyState() == XMLHttpRequest.DONE) {
        if (xhr.getStatus() != 200) {
          listener.onFailure();
        } else {
          listener.onSuccess(xhr.getResponseText());
        }
      }
    }
  });
  setOnProgress(request, listener);
  request.open("GET", url);
  request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
  request.send();
}

代码示例来源:origin: libgdx/libgdx

public void loadText (String url, final AssetLoaderListener<String> listener) {
  XMLHttpRequest request = XMLHttpRequest.create();
  request.setOnReadyStateChange(new ReadyStateChangeHandler() {
    @Override
    public void onReadyStateChange (XMLHttpRequest xhr) {
      if (xhr.getReadyState() == XMLHttpRequest.DONE) {
        if (xhr.getStatus() != 200) {
          listener.onFailure();
        } else {
          listener.onSuccess(xhr.getResponseText());
        }
      }
    }
  });
  setOnProgress(request, listener);
  request.open("GET", url);
  request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
  request.send();
}

代码示例来源:origin: libgdx/libgdx

public void loadBinary (final String url, final AssetLoaderListener<Blob> listener) {
  XMLHttpRequest request = XMLHttpRequest.create();        
  request.setOnReadyStateChange(new ReadyStateChangeHandler() {
    @Override
    public void onReadyStateChange (XMLHttpRequest xhr) {
      if (xhr.getReadyState() == XMLHttpRequest.DONE) {
        if (xhr.getStatus() != 200) {
          listener.onFailure();
        } else {
          Int8Array data = TypedArrays.createInt8Array(xhr.getResponseArrayBuffer());
          listener.onSuccess(new Blob(data));
        }
      }
    }
  });
  setOnProgress(request, listener);
  request.open("GET", url);
  request.setResponseType(ResponseType.ArrayBuffer);
  request.send();
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Initiates a request with no request data. This simply calls
 * {@link #send(String)} with <code>null</code> as an argument, because the
 * no-argument <code>send()</code> method is unavailable on Firefox.
 */
public final void send() {
 send(null);
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

/**
 * Initiates a request with no request data. This simply calls
 * {@link #send(String)} with <code>null</code> as an argument, because the
 * no-argument <code>send()</code> method is unavailable on Firefox.
 */
public final void send() {
 send(null);
}

代码示例来源:origin: net.wetheinter/gwt-user

/**
 * Initiates a request with no request data. This simply calls
 * {@link #send(String)} with <code>null</code> as an argument, because the
 * no-argument <code>send()</code> method is unavailable on Firefox.
 */
public final void send() {
 send(null);
}

代码示例来源:origin: com.google.gwt/gwt-servlet

xmlHttpRequest.send(requestData);
} catch (JavaScriptException e) {
 throw new RequestException(e.getMessage());

代码示例来源:origin: stackoverflow.com

void postJson(Map<String, String> map, String url) {
  XMLHttpRequest request = new XMLHttpRequest();

  // Post asynchronously
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

  // Encode the data as JSON before sending
  String mapAsJson = JSON.stringify(toJsObject(map));
  request.send(mapAsJson);
}

jsweet.lang.Object toJsObject(Map<String, String> map) {
  jsweet.lang.Object jsObject = new jsweet.lang.Object();

  // Put the keys and values from the map into the object
  for (Entry<String, String> keyVal : map.entrySet()) {
    jsObject.$set(keyVal.getKey(), keyVal.getValue());
  }
  return jsObject;
}

代码示例来源:origin: com.badlogicgames.gdx/gdx-backend-gwt

public void loadBinary (final String url, final AssetLoaderListener<Blob> listener) {
  XMLHttpRequest request = XMLHttpRequest.create();        
  request.setOnReadyStateChange(new ReadyStateChangeHandler() {
    @Override
    public void onReadyStateChange (XMLHttpRequest xhr) {
      if (xhr.getReadyState() == XMLHttpRequest.DONE) {
        if (xhr.getStatus() != 200) {
          listener.onFailure();
        } else {
          Int8Array data = TypedArrays.createInt8Array(xhr.getResponseArrayBuffer());
          listener.onSuccess(new Blob(data));
        }
      }
    }
  });
  setOnProgress(request, listener);
  request.open("GET", url);
  request.setResponseType(ResponseType.ArrayBuffer);
  request.send();
}

代码示例来源:origin: com.badlogicgames.gdx/gdx-backend-gwt

public void loadText (String url, final AssetLoaderListener<String> listener) {
  XMLHttpRequest request = XMLHttpRequest.create();
  request.setOnReadyStateChange(new ReadyStateChangeHandler() {
    @Override
    public void onReadyStateChange (XMLHttpRequest xhr) {
      if (xhr.getReadyState() == XMLHttpRequest.DONE) {
        if (xhr.getStatus() != 200) {
          listener.onFailure();
        } else {
          listener.onSuccess(xhr.getResponseText());
        }
      }
    }
  });
  setOnProgress(request, listener);
  request.open("GET", url);
  request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
  request.send();
}

代码示例来源:origin: playn/playn

private RFuture<XMLHttpRequest> doXhr(final String path, XMLHttpRequest.ResponseType rtype) {
 final RPromise<XMLHttpRequest> result = RPromise.create();
 XMLHttpRequest xhr = XMLHttpRequest.create();
 // IE needs the XHR to be opened before setting the response type
 if (LOG_XHR_SUCCESS) plat.log().debug("xhr.open('GET', '" + path + "')...");
 xhr.open("GET", path);
 xhr.setResponseType(rtype);
 xhr.setOnReadyStateChange(new ReadyStateChangeHandler() {
  @Override public void onReadyStateChange(XMLHttpRequest xhr) {
   int readyState = xhr.getReadyState();
   if (readyState == XMLHttpRequest.DONE) {
    int status = xhr.getStatus();
    // status code 0 will be returned for non-http requests, e.g. file://
    if (status != 0 && (status < 200 || status >= 400)) {
     plat.log().error("xhr::onReadyStateChange[" + path + "]" +
              "(readyState = " + readyState + "; status = " + status + ")");
     result.fail(new Exception("Error getting " + path + " : " + xhr.getStatusText()));
    } else {
     if (LOG_XHR_SUCCESS) plat.log().debug("xhr::onReadyStateChange[" + path + "]" +
                        "(readyState = " + readyState +
                        "; status = " + status + ")");
     result.succeed(xhr);
    }
   }
  }
 });
 if (LOG_XHR_SUCCESS) plat.log().debug("xhr.send()...");
 xhr.send();
 return result;
}

代码示例来源:origin: io.playn/playn-html

private RFuture<XMLHttpRequest> doXhr(final String path, XMLHttpRequest.ResponseType rtype) {
 final RPromise<XMLHttpRequest> result = RPromise.create();
 XMLHttpRequest xhr = XMLHttpRequest.create();
 // IE needs the XHR to be opened before setting the response type
 if (LOG_XHR_SUCCESS) plat.log().debug("xhr.open('GET', '" + path + "')...");
 xhr.open("GET", path);
 xhr.setResponseType(rtype);
 xhr.setOnReadyStateChange(new ReadyStateChangeHandler() {
  @Override public void onReadyStateChange(XMLHttpRequest xhr) {
   int readyState = xhr.getReadyState();
   if (readyState == XMLHttpRequest.DONE) {
    int status = xhr.getStatus();
    // status code 0 will be returned for non-http requests, e.g. file://
    if (status != 0 && (status < 200 || status >= 400)) {
     plat.log().error("xhr::onReadyStateChange[" + path + "]" +
              "(readyState = " + readyState + "; status = " + status + ")");
     result.fail(new Exception("Error getting " + path + " : " + xhr.getStatusText()));
    } else {
     if (LOG_XHR_SUCCESS) plat.log().debug("xhr::onReadyStateChange[" + path + "]" +
                        "(readyState = " + readyState +
                        "; status = " + status + ")");
     result.succeed(xhr);
    }
   }
  }
 });
 if (LOG_XHR_SUCCESS) plat.log().debug("xhr.send()...");
 xhr.send();
 return result;
}

代码示例来源:origin: thothbot/parallax

public void loadText (final FileListener<String> listener) {
  XMLHttpRequest request = XMLHttpRequest.create();
  request.setOnReadyStateChange(new ReadyStateChangeHandler() {
    @Override
    public void onReadyStateChange (XMLHttpRequest xhr) {
      if (xhr.getReadyState() == XMLHttpRequest.DONE) {
        if (xhr.getStatus() != 200) {
          listener.onFailure();
        } else {
          listener.onSuccess(xhr.getResponseText());
        }
      }
    }
  });
  setOnProgress(request, listener);
  request.open("GET", getUrl());
  request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
  request.send();
}

代码示例来源:origin: thothbot/parallax

public void loadBinary (final FileListener<Blob> listener) {
  XMLHttpRequest request = XMLHttpRequest.create();
  request.setOnReadyStateChange(new ReadyStateChangeHandler() {
    @Override
    public void onReadyStateChange (XMLHttpRequest xhr) {
      if (xhr.getReadyState() == XMLHttpRequest.DONE) {
        if (xhr.getStatus() != 200) {
          listener.onFailure();
        } else {
          Int8Array data = TypedArrays.createInt8Array(xhr.getResponseArrayBuffer());
          listener.onSuccess(new Blob(data));
        }
      }
    }
  });
  setOnProgress(request, listener);
  request.open("GET", getUrl());
  request.setResponseType(XMLHttpRequest.ResponseType.ArrayBuffer);
  request.send();
}

代码示例来源:origin: sriharshachilakapati/SilenceEngine

@Override
public Promise<Long> sizeInBytes()
{
  return new Promise<>((resolve, reject) ->
  {
    XMLHttpRequest request = XMLHttpRequest.create();
    request.open("HEAD", getAbsolutePath());
    request.setOnReadyStateChange(xhr ->
    {
      if (request.getStatus() == 404)
        resolve.invoke(-1L);
      else if (request.getReadyState() == XMLHttpRequest.DONE && request.getStatus() == 200)
        try
        {
          resolve.invoke(Long.parseLong(request.getResponseHeader("Content-Length")));
        }
        catch (Exception e)
        {
          resolve.invoke(0L);
        }
    });
    request.send();
  });
}

代码示例来源:origin: sriharshachilakapati/SilenceEngine

@Override
public Promise<Boolean> exists()
{
  return new Promise<>((resolve, reject) ->
  {
    XMLHttpRequest request = XMLHttpRequest.create();
    request.open("HEAD", getAbsolutePath());
    request.setOnReadyStateChange(xhr ->
    {
      if (request.getStatus() == 404)
        resolve.invoke(false);
      else if (request.getReadyState() == XMLHttpRequest.DONE && request.getStatus() == 200)
        resolve.invoke(true);
    });
    request.send();
  });
}

代码示例来源:origin: org.atmosphere/atmosphere-gwt-client

xmlHttpRequest.send();
} catch (JavaScriptException e) {
  if (xmlHttpRequest != null) {

代码示例来源:origin: sriharshachilakapati/SilenceEngine

@Override
  public void readTextFile(FilePath file, UniCallback<String> onComplete, UniCallback<Throwable> onError)
  {
    // Create a XMLHttpRequest to load the file into a direct buffer
    XMLHttpRequest request = XMLHttpRequest.create();
    request.open("GET", file.getAbsolutePath());

    // Set to read as default mode and attach a handler
    request.setResponseType(XMLHttpRequest.ResponseType.Default);
    request.setOnReadyStateChange(xhr ->
    {
      if (request.getReadyState() == XMLHttpRequest.DONE)
      {
        if (request.getStatus() == 200)
          // Invoke the onComplete handler
          onComplete.invoke(request.getResponseText());
        else
          onError.invoke(new SilenceException("Error fetching the file: " + request.getStatusText()));
      }
    });

    // Send the request
    request.send();
  }
}

代码示例来源:origin: sriharshachilakapati/SilenceEngine

@Override
public void readBinaryFile(FilePath file, UniCallback<DirectBuffer> onComplete, UniCallback<Throwable> onError)
{
  // Create a XMLHttpRequest to load the file into a direct buffer
  XMLHttpRequest request = XMLHttpRequest.create();
  request.open("GET", file.getAbsolutePath());
  // Set to read as ArrayBuffer and attach a handler
  request.setResponseType(XMLHttpRequest.ResponseType.ArrayBuffer);
  request.setOnReadyStateChange(xhr ->
  {
    if (request.getReadyState() == XMLHttpRequest.DONE)
    {
      if (request.getStatus() == 200)
        // Invoke the onComplete handler
        onComplete.invoke(new GwtDirectBuffer(request.getResponseArrayBuffer()));
      else
        onError.invoke(new SilenceException("Error fetching the file: " + request.getStatusText()));
    }
  });
  // Send the request
  request.send();
}

相关文章