Skip to content

Instantly share code, notes, and snippets.

@gabbsmo
Created November 7, 2016 14:06
Show Gist options
  • Save gabbsmo/a0df687a12e9daca0469e2bdb779a440 to your computer and use it in GitHub Desktop.
Save gabbsmo/a0df687a12e9daca0469e2bdb779a440 to your computer and use it in GitHub Desktop.
function getCommentCount(url, itemId) {
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,
url: "/_vti_bin/SocialDataService.asmx?op=CountCommentsOnUrl",
type: "POST",
dataType: "xml",
data: soapEnv,
contentType: "text/xml; charset=\"utf-8\"",
}).then(function (data) {
var count = $(data).text();
setCommentsText(count, itemId, url);
});
}
function setCommentsText(count, itemId, url) {
var comments = $('#' + itemId + ' .comments');
comments.html("<span>(" + count + ") <a href='" + url + "'>Comments</a></span>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment