Package com.google.gwt.xhr.client

Examples of com.google.gwt.xhr.client.XMLHttpRequest


      throw new GdxRuntimeException("Unsupported asset type " + type);
    }
  }

  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();
  }
View Full Code Here


    request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
    request.send();
  }

  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();
  }
View Full Code Here

     * Setting the onreadystatechange handler to null gives us the correct
     * behavior in Mozilla but crashes IE. That is why we have chosen to fixed
     * this in Java by nulling out our reference to the XmlHttpRequest object.
     */
    if (xmlHttpRequest != null) {
      XMLHttpRequest xmlHttp = xmlHttpRequest;
      xmlHttpRequest = null;

      xmlHttp.clearOnReadyStateChange();
      xmlHttp.abort();

      cancelTimer();
    }
  }
View Full Code Here

    /*
     * We cannot use cancel here because it would clear the contents of the
     * JavaScript XmlHttpRequest object so we manually null out our reference to
     * the JavaScriptObject
     */
    final XMLHttpRequest xhr = xmlHttpRequest;
    xmlHttpRequest = null;

    String errorMsg = getBrowserSpecificFailure(xhr);
    if (errorMsg != null) {
      Throwable exception = new RuntimeException(errorMsg);
View Full Code Here

   * @throws NullPointerException if request data has not been set
   * @throws NullPointerException if a request callback has not been set
   */
  private Request doSend(String requestData, final RequestCallback callback)
      throws RequestException {
    XMLHttpRequest xmlHttpRequest = XMLHttpRequest.create();

    try {
      if (user != null && password != null) {
        xmlHttpRequest.open(httpMethod, url, user, password);
      } else if (user != null) {
        xmlHttpRequest.open(httpMethod, url, user);
      } else {
        xmlHttpRequest.open(httpMethod, url);
      }
    } catch (JavaScriptException e) {
      RequestPermissionException requestPermissionException = new RequestPermissionException(
          url);
      requestPermissionException.initCause(new RequestException(e.getMessage()));
      throw requestPermissionException;
    }

    setHeaders(xmlHttpRequest);

    final Request request = new Request(xmlHttpRequest, timeoutMillis, callback);

    // Must set the onreadystatechange handler before calling send().
    xmlHttpRequest.setOnReadyStateChange(new ReadyStateChangeHandler() {
      public void onReadyStateChange(XMLHttpRequest xhr) {
        if (xhr.getReadyState() == XMLHttpRequest.DONE) {
          xhr.clearOnReadyStateChange();
          request.fireOnResponseReceived(callback);
        }
      }
    });

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

    return request;
View Full Code Here

TOP

Related Classes of com.google.gwt.xhr.client.XMLHttpRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.