HTML Sharepoint Context Information

I am creating a SPA inside Sharepoint 2013 by uploading javascript and html files to a document library. I am trying to get current user information by accessing context information through sp.js. But I get this error:

_spPageContextInfo is not defined 

In my index.aspx file, I include the following js:

 <script src="/_layouts/1033/init.js"></script> <script src="/_layouts/MicrosoftAjax.js"></script> <script src="/_layouts/sp.core.js"></script> <script src="/_layouts/sp.runtime.js"></script> <script src="/_layouts/sp.js"></script> 

I also included this at the beginning of the index.aspx file:

 <%@ Page language="C#" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> 

In my js file, I have the following code:

 $(document).ready(function() { // wait for the sharepoint javascript libraries to load, then call the function 'Initialize' ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js"); }); function runCode() { var userid= _spPageContextInfo.userId; } 

It should be noted that I use Angular JS to build the application, and I use the Angular UI router library to navigate between pages.

The document library is inside a child object in the side collection.

eg.

intra.xxx.xxx/xxx/index.aspx

Any suggestions?

+5
source share
1 answer

It turned out that I clearly did not have sharepoint dependencies on my index.aspx file.

Decision

Beginning of the .aspx index:

 <%@ Page language="C#" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <!DOCTYPE html> 

Scripts in title:

 <!--Sharepoint Dependencies--> <script src="/_layouts/1033/init.js"></script> <script src="/_layouts/1033/core.js"></script> <script src="/_layouts/MicrosoftAjax.js"></script> <script src="/_layouts/SP.Core.js"></script> <script src="/_layouts/SP.Runtime.js"></script> <script src="/_layouts/SP.js"></script> <script src="/_layouts/SP.UI.Dialog.js"></script> <script src="/_layouts/ScriptResx.ashx?culture=en%2Dus&name=SP%2ERes"></script> 

Body

 <!-- required: SharePoint FormDigest --> <form runat="server"> <SharePoint:FormDigest runat="server"></SharePoint:FormDigest> </form> 
0
source

Source: https://habr.com/ru/post/1241423/


All Articles