本文整理了Java中com.google.gwt.xhr.client.XMLHttpRequest.setResponseType()
方法的一些代码示例,展示了XMLHttpRequest.setResponseType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLHttpRequest.setResponseType()
方法的具体详情如下:
包路径:com.google.gwt.xhr.client.XMLHttpRequest
类名称:XMLHttpRequest
方法名:setResponseType
[英]Sets the response type.
See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute
[中]设置响应类型。
见http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute
代码示例来源: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 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
/**
* Sets the response type.
* <p>
* See <a href="http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute"
* >http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute</a>
*
* @param responseType the type of response desired. See {@link ResponseType}
* for limitations on using the different values
*/
public final void setResponseType(ResponseType responseType) {
this.setResponseType(responseType.getResponseTypeString());
}
代码示例来源:origin: net.wetheinter/gwt-user
/**
* Sets the response type.
* <p>
* See <a href="http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute"
* >http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute</a>
*
* @param responseType the type of response desired. See {@link ResponseType}
* for limitations on using the different values
*/
public final void setResponseType(ResponseType responseType) {
this.setResponseType(responseType.getResponseTypeString());
}
代码示例来源:origin: com.vaadin.external.gwt/gwt-user
/**
* Sets the response type.
* <p>
* See <a href="http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute"
* >http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute</a>
*
* @param responseType the type of response desired. See {@link ResponseType}
* for limitations on using the different values
*/
public final void setResponseType(ResponseType responseType) {
this.setResponseType(responseType.getResponseTypeString());
}
代码示例来源: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: 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 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 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();
}
内容来源于网络,如有侵权,请联系作者删除!