SP.ClientContext.executeQueryAsync method (sp.js)

Executes the current pending request asynchronously on the server.

Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

SP.ClientContext.executeQueryAsync(succeededCallback, failedCallback)

Parameters

  • succeededCallback
    A function or a delegate of the method to call if the request executes successfully.

  • failedCallback
    A function or a delegate of the method to call if the request fails to execute.

Remarks

The executeQueryAsync method is inherited from the SP.ClientRuntimeContext object. This virtual method is asynchronous, which means that the code will continue to be executed without waiting for the server to respond.

Example

The following code example shows how to use the executeQueryAsync method.

function retrieveWebSite(siteUrl) {
    var clientContext = new SP.ClientContext(siteUrl);
    this.oWebsite = clientContext.get_web();

    clientContext.load(this.oWebsite);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded(sender, args) {
    alert('Title: ' + this.oWebsite.get_title() + 
        ' Description: ' + this.oWebsite.get_description());
}
    
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}

See also

Other resources

SP.ClientContext

Complete basic operations using JavaScript library code in SharePoint 2013