JAVASCRIPT

Alongside the Managed .NET Client-Side Object Model (Managed CSOM) is the JavaScript Client Object Model (JS CSOM).

NOTE See the previous section, “Managed Code (.NET),” for background foundational information about the CSOM that isn’t repeated in this section.

The primary purpose of the JS CSOM is to allow JavaScript code running on pages within the context of SharePoint to talk back to SharePoint without requiring a full-page postback. It is not designed or intended for developers to use outside of the context of pages served from SharePoint.

Similar to the Managed CSOM, the JS CSOM also is built to batch requests to ensure performance. However, one of the fundamental differences is that the JS CSOM is designed with asynchronous calls and callbacks in mind. This ensures that transactions that take some time to complete don’t potentially block the calling thread, possibly impacting the UI of your application.

To access the JS CSOM the calling page must reference the following two files:

  • SP.Runtime.js
  • SP.js

Each of these is located in the /_layouts/15/ directory under each SharePoint site; for example, http://myserver/sitename/_layouts/15/SP.js.

You can also find these files on any SharePoint 2013 server in the following location:

%ProgramFiles%\Common Files\Microsoft Shared\
web server extensions\15\TEMPLATE\LAYOUTS
NOTE Although the JS CSOM libraries are available, sometimes simple REST/OData HTTP-based calls might be just as easy for you to use. If you ...

Get Beginning SharePoint 2013 Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.