Export (0) Print
Expand All

SP.ClientContext object (sp.js)

SharePoint 2013

Represents the context for objects and operations.

var object = new SP.ClientContext()

The ClientContext object has the following members.

Constructor

The ClientContext object has the following constructor.

Constructor

Description

ClientContext

Initializes a new instance of the ClientContext object for the specified SharePoint site.

Methods

The ClientContext object has the following methods.

Method

Description

castTo

Casts the specified client object to a derived type.

dispose

Disposes of the context.

executeQueryAsync

Executes the current pending request asynchronously on the server.

load

Retrieves the properties of a client object from the server.

loadQuery

Retrieves an enumerable sequence of child client objects from the specified collection.

onExecutingWebRequest

Raises the ExecutingWebRequest event.

parseObjectFromJsonString

Parses the specified JavaScript Object Notation (JSON) string and gets an object from it.

Properties

The ClientContext object has the following properties.

Property

Description

applicationName

Gets or sets the name of the runtime where the current client application is located.

current

Gets the current client context of the client-side object model (CSOM) runtime.

formDigestHandlingEnabled

Gets or sets a value that indicates whether form digest handling is enabled.

hasPendingRequest

Gets a value that indicates whether the client context has a pending request.

pendingRequest

Gets the client request that is sent to the server when the next executeQueryAsync method is executed.

requestTimeout

Gets or sets the request timeout in milliseconds

serverLibraryVersion

Gets the build version of Microsoft.SharePoint.Client.ServerRuntime.dll on the server.

serverSchemaVersion

Gets the schema version of Microsoft.SharePoint.Client.ServerRuntime.dll on the server.

serverVersion

Gets the version of the current instance of SharePoint 2013.

site

Gets the site collection that is associated with the client context.

traceCorrelationId

Gets or sets the trace correlation ID used by the server.

url

Gets the URL associated with the runtime context.

web

Gets the website that is associated with the client context.

Use the ClientContext object to return context information about the current web application, site, site collection, or server version.

The following code example creates an instance of the client context object, which is used to access the SharePoint object model. The example gets the current context by using the current property.

var clientContext;
var website;

// Make sure the SharePoint script file 'sp.js' is loaded before your
// code runs.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

// Create an instance of the current context.
function sharePointReady() {
    clientContext = SP.ClientContext.get_current();
    website = clientContext.get_web();

    clientContext.load(website);
    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
}
function onRequestSucceeded() {
    alert(website.get_url());
}
function onRequestFailed(sender, args) {
    alert('Error: ' + args.get_message());
}

Community Additions

ADD
Show:
© 2014 Microsoft