Skip to content

How to call method with JS callback #6

Description

@hosek

Hi,
is possible to call method with JS callback?
Example:

Library.prototype.fetch = function(url,cb,scope) {
        var request = new XMLHttpRequest();

    request.onreadystatechange = function() {
        if (request.readyState==4 && request.status==200) {
            cb.call(scope,request.responseText);
        }
    }
        request.open("GET",url,true);
        request.send();
}

In JS call looks like this:

instanceOfLibrary.fetch('_URL_', function(data) {document.getElementById("output").innerHTML = "<h2>Fetched:</h2><pre>"+data+"</pre>";

If yes, could I ask how to define the callback in interface?

@Method("instanceOfLibrary.fetch")
void fetch(String url, ???? , Callback<String> callback);

Thank you in advance for any hint!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions