以下示例演示了如何在客户端通过 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 库添加注释
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');