يؤدي الوصول إلى قائمة من تطبيق الويب على الموقع المضيف إلى رفض الوصول

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/60702

سؤال

أحاول الحصول على عنوان القائمة الموجودة على موقع المضيف من تطبيق مستضاف على SharePoint باستخدام csom (javascript).لقد قمت بإضافة إذن على ملف البيان واخترت القائمة ولكن لا يزال يتم رفض الوصول إلى ExecuterQueryAsync.هنا هو الكود الخاص بي:

  hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
  var hostcontext = new SP.ClientContext(hostweburl);
  var oList = hostcontext.get_web().get_lists().getByTitle('SliderList');
  var camlQuery = new SP.CamlQuery();
  camlQuery.set_viewXml(' som query to get proper items')
  this.collListItem = oList.getItems(camlQuery);

   hostcontext.load(collListItem);

   hostcontext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

لا ينتقل إلى onQuerySuccess أو onQueryFailed، ويقول إنه تم رفض الوصول إلى SP_ClientRuntimeContext$executeQueryAsync، sp.runtime.debug.js، السطر 3103

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

المحلول

تحتاج بالفعل إلى إنشاء SP.ClientContext لـ ويب التطبيق و أ SP.AppContextSite للويب المضيف.للحصول على مرجع لقائمة في الويب المضيف، جرب ما يلي:

// Get the ClientContext for the app web
clientContext = new SP.ClientContext.get_current();
// Use the host web URL to get a parent context - this allows us to get data from the parent
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
parentCtx = new SP.AppContextSite(clientContext, hostweburl);
parentWeb = parentCtx.get_web();
parentList = parentWeb.get_lists().getByTitle("SliderList");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top