سؤال

لقد قمت بإنشاء صفحة مخصصة مخصصة. وأريد الوصول إلى بيانات قائمة SharePoint في هذه الصفحة الرئيسية باستخدام JavaScript.

أكتب البرنامج النصي التالي للوصول إلى البيانات، لكنه يقدم خطأ "sp.clientcontext.get_current () null undefined" giveacodicetagpre.

كيف يمكنني القيام بذلك؟

هل كانت مفيدة؟

المحلول

To use Client OM, you need a reference to SP.js

For production:

<SharePoint:ScriptLink Name="sp.js" runat="server" OnDemand="true" Localizable="false" />

For development purpose:

<SharePoint:ScriptLink Name="sp.debug.js" runat="server" OnDemand="true" Localizable="false" />

Moreover, there is also another way to declare it using the ExecuteOrDelauUntilScriptLoaded method:

var clientContext;

ExecuteOrDelayUntilScriptLoaded(initialize,"SP.js");

function initialize() {

  this.clientContext = SP.ClientContext.get_current();

}

Happy SharePointing!

نصائح أخرى

Try this...

$(document).ready(function(){


ExecuteOrDelayUntilScriptLoaded(GetDocuments(), "sp.js");

setTimeout(function() {


var listurl = yoursite +"/_vti_bin/lists.asmx";
var listname = "listname";
var query = "";
var soapEnv = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>"+
              "<listName>" + listname + "</listName> <query><Query>"+query+"</Query></query>"+
              "<viewFields><ViewFields><FieldRef Name='LinkFilename' /></ViewFields></viewFields>"+
              "</GetListItems> </soapenv:Body></soapenv:Envelope>";

$.ajax
({
   url: listurl,
   beforeSend: function (xhr) {
       xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
   },
   type: "POST",
   dataType: "xml",
   data: soapEnv,
   async:false,
   complete: function (xData, status) {
  $(xData.responseXML).find("z\\:row").each(function () {
            var title = $(this).attr("ows_Title");
        });
   },
   contentType: "text/xml; charset=utf-8"
});


}, 5000);


});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top