When you use Jom for SharePoint 2013, the following issues occur:
REFERENCEERROR:SP is not defined
After repeated trials and searches, the following two methods are obtained:
First, the direct reference JS file, the reference order is important:
<Scripttype= "Text/javascript"src= "Https://nn.sharepoint.com/teams/ap1/gct/_layouts/15/MicrosoftAjax.js"></Script><Scripttype= "Text/javascript"src= "Https://nn.sharepoint.com/teams/ap1/gct/_layouts/15/SP.Runtime.js"></Script><Scripttype= "Text/javascript"src= "Https://nn.sharepoint.com/teams/ap1/gct/_layouts/15/SP.js"></Script><Scripttype= "Text/javascript"src= "Https://nn.sharepoint.com/teams/ap1/gct/_layouts/15/SP.RequestExecutor.js"></Script><Scriptsrc= "Https://nn.sharepoint.com/teams/ap1/gct/SiteAssets/jquery-1.9.1.js"></Script><Scripttype= "Text/javascript">varHostweburl="HTTPS://NN.SHAREPOINT.COM/TEAMS/AP1/GCT"; $ (document). Ready (function () { varScriptbase=Hostweburl+ "/_layouts/15/"; //executeordelayuntilscriptloaded (initializepage, "sp.js");initializepage ();});functionInitializepage () {varContext=SP. Clientcontext.get_current (); varUser=Context.get_web (). Get_currentuser (); //This code runs when the DOM was ready and creates a context object whichis needed to use the SharePoint object Model $ (document). Ready (function() {getusername (); }); //This function prepares, loads, and then executes a SharePoint query toget the current users informationfunctionGetUserName () {context.load (user); Context.executequeryasync (ongetusernamesuccess, Ongetusernamefail); } //This function was executed if the above call is successful //It replaces the contents of the ' message ' element with the user name functionongetusernamesuccess () {$ ('#message'). Text ('Hello' +user.get_title ()); } //This function was executed if the above call fails functionongetusernamefail (sender, args) {alert ('Failed to get user name. Error:' +args.get_message ()); }}
View Code
Ii. the $.getscript method using jquery
<Scripttype= "Text/javascript">varHostweburl="Https://nike.sharepoint.com/teams/ap1/gctech"; $ (document). Ready (function () { varScriptbase=Hostweburl+ "/_layouts/15/"; varScriptbase=Hostweburl+ "/_layouts/15/"; $.getscript (Scriptbase+ "MicrosoftAjax.js"). Then (function(data) {return$.getscript (Scriptbase+ "SP. Runtime.js");}). Then (function(data) {return$.getscript (Scriptbase+ "Sp.js");}). Then (function(data) {$.getscript (scriptbase+ "SP. Requestexecutor.js");}). Then (function(data) {alert ("Load as Order");/*var ctx = new SP. ClientContext (appweburl), factory = new SP. Proxywebrequestexecutorfactory (Appweburl), web; Ctx.set_webrequestexecutorfactory (Factory); web = Ctx.get_web (); Ctx.load (web); Ctx.executequeryasync (function () {///log the name of the app Web to the console Console.log (Web.get_title () ); }, function (sender, args) {Console.log ("Error:" + args.get_message ()); });*/});</Script>
View Code
Using JOM issues in the Provider Hosted app