Skip to content

Instantly share code, notes, and snippets.

@vgrem
Created May 13, 2013 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/5571187 to your computer and use it in GitHub Desktop.
Save vgrem/5571187 to your computer and use it in GitHub Desktop.
jQuery wrapper for retiring comment count via SharePoint Social Data Web Service
function CountCommentsOnUrl(url,result)
{
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> \
<CountCommentsOnUrl xmlns='http://microsoft.com/webservices/SharePointPortalServer/SocialDataService'> \
<url>" + url + "</url> \
</CountCommentsOnUrl> \
</soap:Body> \
</soap:Envelope>";
$.ajax({
pageurl: url,
result: result,
url: "/_vti_bin/SocialDataService.asmx?op=CountCommentsOnUrl",
type: "POST",
dataType: "xml",
data: soapEnv,
contentType: "text/xml; charset=\"utf-8\"",
success: function(data, status, xhr){
if(this.result !== undefined) {
var commentCount = $('CountCommentsOnUrlResponse', data).find('CountCommentsOnUrlResult').text();
this.result(commentCount);
}
}
});
}
$(function() {
$('span.comments').each(function() {
var pageUrl = $(this).attr('pageurl');
var comment = $(this);
CountCommentsOnUrl(pageUrl,function(commentCount){
comment.text(commentCount);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment