当前位置: 首页>>代码示例>>Java>>正文


Java XMLHttpRequest类代码示例

本文整理汇总了Java中com.google.gwt.xhr.client.XMLHttpRequest的典型用法代码示例。如果您正苦于以下问题:Java XMLHttpRequest类的具体用法?Java XMLHttpRequest怎么用?Java XMLHttpRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XMLHttpRequest类属于com.google.gwt.xhr.client包,在下文中一共展示了XMLHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scriptSync

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * Load javascript files synchronously and evalue/execute them directly too.
 * You can also add them at the head of the html-document with
 * Vertx.addLibrariesJs(), which is the same but more 'to the rules'. You
 * need this if you want to use the javascript right after loading it (which
 * is normal in most cases).
 * 
 * @param jss
 *            javascript file(s)
 * @return this
 */
public Fluent scriptSync(String... jss) {
	if (!GWT.isClient()) {
		return this;
	}
	for (String js : jss) {
		XMLHttpRequestSyc xhr = (XMLHttpRequestSyc) XMLHttpRequestSyc.create();
		xhr.setOnReadyStateChange(a -> {
			if (a.getReadyState() == XMLHttpRequest.DONE && a.getStatus() == 200) {
				eval(xhr.getResponseText());
			}
		});
		xhr.open("GET", js, false);
		xhr.send();
	}
	return this;
}
 
开发者ID:nielsbaloe,项目名称:vertxui,代码行数:28,代码来源:Fluent.java

示例2: ajax

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public static <I, O> void ajax(String protocol, String url, I model, ObjectMapper<I> inMapper,
		ObjectMapper<O> outMapper, BiConsumer<Integer, O> handler) {
	XMLHttpRequest xhr = XMLHttpRequest.create();
	xhr.setOnReadyStateChange(a -> {
		if (handler == null || xhr.getReadyState() != 4) {
			return;
		}
		O result = null;
		if (xhr.getStatus() == 200) {
			result = out(xhr.getResponseText(), outMapper);
		}
		handler.accept(xhr.getStatus(), result);
	});
	xhr.open(protocol, url);
	xhr.send(in(model, inMapper));
}
 
开发者ID:nielsbaloe,项目名称:vertxui,代码行数:17,代码来源:Pojofy.java

示例3: jsLogout

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public JavaScriptObject jsLogout(final JavaScriptObject onSuccess, final JavaScriptObject onFailure) throws Exception {
	return Utils.publishCancellable(requestLogout(new CallbackAdapter<XMLHttpRequest, XMLHttpRequest>() {

		@Override
		protected void doWork(XMLHttpRequest aResult) throws Exception {
			Utils.invokeJsFunction(onSuccess);
		}

		@Override
		public void onFailure(XMLHttpRequest reason) {
			try {
				Utils.executeScriptEventVoid(onFailure, onFailure, Utils.toJs(reason.getStatusText()));
			} catch (Exception ex) {
				Logger.getLogger(AppClient.class.getName()).log(Level.SEVERE, null, ex);
			}
		}
	}));
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:19,代码来源:AppClient.java

示例4: requestLogout

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public Cancellable requestLogout(final Callback<XMLHttpRequest, XMLHttpRequest> aCallback) throws Exception {
	String query = param(PlatypusHttpRequestParams.TYPE, String.valueOf(Requests.rqLogout));
	return startApiRequest(null, query, null, RequestBuilder.GET, null, new CallbackAdapter<XMLHttpRequest, XMLHttpRequest>() {

		@Override
		protected void doWork(XMLHttpRequest aResult) throws Exception {
			principal = null;
			aCallback.onSuccess(aResult);
		}

		@Override
		public void onFailure(XMLHttpRequest reason) {
			aCallback.onFailure(reason);
		}

	});
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:18,代码来源:AppClient.java

示例5: syncRequest

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public XMLHttpRequest2 syncRequest(String aUrl, ResponseType aResponseType, String aBody, RequestBuilder.Method aMethod) throws Exception {
	final XMLHttpRequest2 req = XMLHttpRequest.create().<XMLHttpRequest2> cast();
	aUrl = Loader.URL_QUERY_PROCESSOR.process(aUrl);
	req.open(aMethod.toString(), aUrl, false);
	interceptRequest(req);
	/*
	 * Since W3C standard about sync XmlHttpRequest and response type. if
	 * (aResponseType != null && aResponseType != ResponseType.Default)
	 * req.setResponseType(aResponseType);
	 */
	req.setRequestHeader("Pragma", "no-cache");
	if (aBody != null)
		req.send(aBody);
	else
		req.send();
	if (req.getStatus() == Response.SC_OK)
		return req;
	else
		throw new Exception(req.getStatus() + " " + req.getStatusText());
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:21,代码来源:AppClient.java

示例6: loadText

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
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();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:20,代码来源:AssetDownloader.java

示例7: loadBinary

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
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();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:21,代码来源:AssetDownloader.java

示例8: createResponse

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
Response createResponse(XMLHttpRequest xmlHttpRequest) {
    return new ResponseImpl(xmlHttpRequest) {

        @Override
        public int getStatusCode() {
          /*
           * http://code.google.com/p/google-web-toolkit/issues/detail?id=5031
           *
           * The XMLHTTPRequest object in IE will return a status code of 1223 and drop some
           * response headers if the server returns a HTTP/204.
           *
           * This issue is fixed in IE10.
           */
            int statusCode = super.getStatusCode();
            return (statusCode == 1223) ? SC_NO_CONTENT : statusCode;
        }
    };
}
 
开发者ID:growbit,项目名称:turbogwt-http,代码行数:20,代码来源:Request.java

示例9: cancel

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * Cancels a pending request. If the request has already been canceled or if
 * it has timed out no action is taken.
 */
public void cancel() {
/*
 * There is a strange race condition that occurs on Mozilla when you cancel
 * a request while the response is coming in. It appears that in some cases
 * the onreadystatechange handler is still called after the handler function
 * has been deleted and during the call to XmlHttpRequest.abort(). So we
 * null the xmlHttpRequest here and that will prevent the
 * fireOnResponseReceived method from calling the callback function.
 * 
 * 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();
    }
}
 
开发者ID:growbit,项目名称:turbogwt-http,代码行数:28,代码来源:Request.java

示例10: isPending

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * Returns true if this request is waiting for a response.
 *
 * @return true if this request is waiting for a response
 */
public boolean isPending() {
    if (xmlHttpRequest == null) {
        return false;
    }

    int readyState = xmlHttpRequest.getReadyState();

/*
 * Because we are doing asynchronous requests it is possible that we can
 * call XmlHttpRequest.send and still have the XmlHttpRequest.getReadyState
 * method return the state as XmlHttpRequest.OPEN. That is why we include
 * open although it is nottechnically true since open implies that the
 * request has not been sent.
 */
    switch (readyState) {
        case XMLHttpRequest.OPENED:
        case XMLHttpRequest.HEADERS_RECEIVED:
        case XMLHttpRequest.LOADING:
            return true;
    }

    return false;
}
 
开发者ID:growbit,项目名称:turbogwt-http,代码行数:29,代码来源:Request.java

示例11: fireOnResponseReceived

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public void fireOnResponseReceived(RequestCallback callback) {
    if (xmlHttpRequest == null) {
        // the request has timed out at this point
        return;
    }

    cancelTimer();

/*
 * 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);
        callback.onError(this, exception);
    } else {
        Response response = createResponse(xhr);
        callback.onResponseReceived(this, response);
    }
}
 
开发者ID:growbit,项目名称:turbogwt-http,代码行数:26,代码来源:Request.java

示例12: exists

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@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();
    });
}
 
开发者ID:sriharshachilakapati,项目名称:SilenceEngine,代码行数:22,代码来源:GwtFilePath.java

示例13: readBinaryFile

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@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();
}
 
开发者ID:sriharshachilakapati,项目名称:SilenceEngine,代码行数:25,代码来源:GwtFileReader.java

示例14: readTextFile

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@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();
}
 
开发者ID:sriharshachilakapati,项目名称:SilenceEngine,代码行数:25,代码来源:GwtFileReader.java

示例15: loadShader

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * The GWT shader load is async
 *
 * @param file
 */
public void loadShader(String file, OnTextResourceLoaded listener) {
	XMLHttpRequest request = XMLHttpRequest.create();

	request.setOnReadyStateChange(new ReadyStateChangeHandler() {

		@Override
		public void onReadyStateChange(XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				// ASYNC
				listener.onResourceLoaded(xhr.getResponseText());
			}
		}
	});

	request.open("GET", GWT.getHostPageBaseURL() + shaderPath + file);
	request.send();
}
 
开发者ID:mobialia,项目名称:jmini3d,代码行数:23,代码来源:ResourceLoader.java


注:本文中的com.google.gwt.xhr.client.XMLHttpRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。