简体   繁体   English

Sharepoint如何获取上下文信息。 使用JavaScript

[英]Sharepoint how to Get context info. using javascript

I am developing the website in that i have to fetch the share point list details. 我正在开发网站,因为我必须获取共享点列表详细信息。 when i try in the Google postman its working fine. 当我尝试使用Google邮递员时,它的工作正常。 But when i try in Javascript i faced the 401 issue. 但是当我尝试使用Javascript时,我遇到了401问题。

function loadXMLDoc() {
   $.ajax({
           type: "POST",
           url: “host / sites / _api / contextinfo ",
           beforeSend: function (xhr){ 
             xhr.setRequestHeader("Authentication ", "Basic " + btoa(“username” + ": " + “password”))
           },   
            success: function (msg){
              console.log(msg);   
            }    
  }); 
}

Please help me how to give the share point user details in javascript. 请帮助我如何在javascript中为共享点用户提供详细信息。

Thanks Sundar D. 感谢SundarD。

If your doing AppParts, then this is probably one of the many prefer patterns: var ctxApp = new SP.ClientContext("/"); 如果您正在做AppPart,那么这可能是许多首选模式之一: var ctxApp = new SP.ClientContext("/"); You could probably just do var ctxApp = new SP.ClientContext(); 您可能只是做var ctxApp = new SP.ClientContext(); if generally get Context information. 通常获取上下文信息。

in regards to doing JSON/REST querying there is a little more to it: 关于执行JSON / REST查询,还有更多内容:

This is what i used to get a RequestExecutor information, but should get you the idea of how to do this in SharePoint's JavaScript implementation: 这是我用来获取RequestExecutor信息的方法,但是应该使您了解如何在SharePoint的JavaScript实现中做到这一点:

var executor = new SP.RequestExecutor("/");
executor.executeAsync({
    url: "_api/SP.AppContextSite(@target)/web/lists/getByTitle('tblTestList')/items?@target='" + qsHostUrl + "'&select=BdcIdentity,value",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: getListDataRESTSuccess,
    error: getListDataRESTError
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM