JavaScript SelectRows wait for end request

LabKey Support Forum (Inactive)
JavaScript SelectRows wait for end request jeckels  2014-05-06 09:03
Status: Closed
 
Asynchronous means that you don't get the results from the server immediately as the result of calling LABKEY.Query.selectRows(). Instead, at some point in the future, your success or failure callbacks will be invoked, when the browser gets the response back from the server. When the callback function is invoked, though, it will have the full response from the server. This isn't unique to LabKey's JavaScript API, this is how AJAX works in JavaScript to make requests a web server.

This might be a bit clearer with a simple modification to the example usage in the API docs:

https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.Query.html#.selectRows

<script type="text/javascript">
    function onFailure(errorInfo, options, responseObj)
    {
        if (errorInfo && errorInfo.exception)
            alert("Failure: " + errorInfo.exception);
        else
            alert("Failure: " + responseObj.statusText);
    }

    function onSuccess(data)
    {
        alert("Success! " + data.rowCount + " rows returned.");
    }

    LABKEY.Query.selectRows({
            schemaName: 'lists',
            queryName: 'People',
            columns: ['Name', 'Age'],
            success: onSuccess,
            failure: onFailure
        });
        alert("Immediately after invoking selectRows()");
</script>

In this case, you'll see that the first popup you get is one that says "Immediately after invoking selectRows()". Then, at some point in the future, you'll get a second popup with the success or failure message.

I hope this helps.

Thanks,
Josh