2012-10-29 95 views
3

我正在使用JavaScript來運行一些Web服務(SharePoint 2010 SocialDataServices)。我已經測試了「CountCommentsOnURL」命令沒有任何問題,但是當我嘗試使用「AddComment」命令時,出現以下錯誤:SharePoint 2010 SocialDataService - 無效的安全驗證

「服務器無法處理請求。這個頁面的安全驗證是無效的,在您的Web瀏覽器中單擊Back,刷新頁面,然後再次嘗試您的操作。此頁面的安全驗證無效。單擊Web瀏覽器中的Back,刷新頁面並嘗試操作再次。」

通過互聯網看,我看到一些關於關閉一些安全設置的文章 - 對我來說不是一種選擇。顯然,刷新頁面也不起作用。

任何想法?

回答

0

以下實施例說明如何通過SocialDataServices服務在客戶端發表評論:

實施例1添加評論

//url parameter corresponds to Page Url 
//comment parameter 
function addComment(url,comment) 
{ 
    var soapEnv = 
     "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \ 
       <soap:Body> \ 
        <AddComment xmlns='http://microsoft.com/webservices/SharePointPortalServer/SocialDataService'> \ 
           <url>" + url + "</url> \ 
           <comment>" + comment + "</comment> \ 
           <isHighPriority>false</isHighPriority> \ 
           <title></title> \ 
        </AddComment> \ 
       </soap:Body> \ 
     </soap:Envelope>"; 

    $.ajax({ 
     result: result, 
     url: _spPageContextInfo.webServerRelativeUrl + "/_vti_bin/SocialDataService.asmx", 
     type: "POST", 
     dataType: "xml", 
     data: soapEnv, 
     contentType: "text/xml; charset=\"utf-8\"", 
     beforeSend: function (xhr) { 
         xhr.setRequestHeader("SOAPAction", "http://microsoft.com/webservices/SharePointPortalServer/SocialDataService/AddComment"); 
       }, 
     success: function(data, status, xhr){ 
      //.. 
     } 
    }); 
} 

實施例2使用添加評論SPServices library

function addComment(url,comment) 
{ 

    $().SPServices({ 
     operation: "AddComment", 
     url: url, 
     title:'', 
     comment:comment, 
     completefunc: function (xData, Status) { 
      console.log($(xData.responseXML)); 
     } 
    }); 
} 

用法:

addComment('http://intranet.contoso.com/pages/somenews.aspx','new comment goes here');