I am new to SharePoint and using 2013 classic version. I have created a website and in it, it has list with items. So, I need to trace the number of clicks of each item individually. My code is not working for tracing the number of clicks as the count gets stopped with 1 and doesn't increment then for individual item. But it counts overall clicks of all items in that list. I'm stuck with this for two weeks. Please help me and Many many thanks in advance.
function Getprevcount(linkname) {
var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('abc')/items?$top=1000";
$.ajax({
url: resturl,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var lnt = data.d.results.length;
for (var i = 0; i < lnt; i++) {
if (data.d.results[i].Title == linkname) {
prevcount = data.d.results[i].Count;
}
}
},
error: function (data) {
console.log(data.responseJSON.error);
}
});
}
function Updatecount(updatlink) {
var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('abc')/items?$select=Title&$filter=Name";
//alert(resturl);
prevcount = prevcount + 1;
//alert(prevcount);
$.ajax({
url: resturl,
method: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTPS-Method": "MERGE"
},
data: "{__metadata:{'type':'SP.Data.TestcounterListItem'}, Count:prevcount}",
async: false, success: function (data) {
alert("I'm in Update Count Section");
console.log(prevcount);
},
error: function (data) {
console.log(data.responseJSON.error);
}
});
}